Skip to content

plugin: Introduce explicit locking on the root runner operations #2115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"sync"

"github.com/hashicorp/go-version"
hcl "github.com/hashicorp/hcl/v2"
Expand All @@ -17,6 +18,7 @@ import (

// GRPCServer is a gRPC server for responding to requests from plugins.
type GRPCServer struct {
mu sync.Mutex
runner *tflint.Runner
rootRunner *tflint.Runner
files map[string]*hcl.File
Expand Down Expand Up @@ -50,6 +52,8 @@ func (s *GRPCServer) GetModuleContent(bodyS *hclext.BodySchema, opts sdk.GetModu
module = s.runner.TFConfig.Module
ctx = s.runner.Ctx
case sdk.RootModuleCtxType:
s.mu.Lock()
defer s.mu.Unlock()
module = s.rootRunner.TFConfig.Module
ctx = s.rootRunner.Ctx
default:
Expand Down Expand Up @@ -87,6 +91,8 @@ func (s *GRPCServer) GetFiles(ty sdk.ModuleCtxType) map[string][]byte {
case sdk.SelfModuleCtxType:
return s.runner.Sources()
case sdk.RootModuleCtxType:
// HINT: This is an operation on the root runner,
// but it works without locking since it is obviously readonly.
return s.rootRunner.Sources()
default:
panic(fmt.Sprintf("invalid ModuleCtxType: %s", ty))
Expand Down Expand Up @@ -127,6 +133,8 @@ func (s *GRPCServer) EvaluateExpr(expr hcl.Expression, opts sdk.EvaluateExprOpti
case sdk.SelfModuleCtxType:
runner = s.runner
case sdk.RootModuleCtxType:
s.mu.Lock()
defer s.mu.Unlock()
runner = s.rootRunner
}

Expand Down
Loading