Skip to content

Commit 2d56e0d

Browse files
authored
Introduce explicit locking on the root runner operations (#2115)
1 parent d45c65a commit 2d56e0d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

plugin/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"log"
7+
"sync"
78

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

1819
// GRPCServer is a gRPC server for responding to requests from plugins.
1920
type GRPCServer struct {
21+
mu sync.Mutex
2022
runner *tflint.Runner
2123
rootRunner *tflint.Runner
2224
files map[string]*hcl.File
@@ -50,6 +52,8 @@ func (s *GRPCServer) GetModuleContent(bodyS *hclext.BodySchema, opts sdk.GetModu
5052
module = s.runner.TFConfig.Module
5153
ctx = s.runner.Ctx
5254
case sdk.RootModuleCtxType:
55+
s.mu.Lock()
56+
defer s.mu.Unlock()
5357
module = s.rootRunner.TFConfig.Module
5458
ctx = s.rootRunner.Ctx
5559
default:
@@ -87,6 +91,8 @@ func (s *GRPCServer) GetFiles(ty sdk.ModuleCtxType) map[string][]byte {
8791
case sdk.SelfModuleCtxType:
8892
return s.runner.Sources()
8993
case sdk.RootModuleCtxType:
94+
// HINT: This is an operation on the root runner,
95+
// but it works without locking since it is obviously readonly.
9096
return s.rootRunner.Sources()
9197
default:
9298
panic(fmt.Sprintf("invalid ModuleCtxType: %s", ty))
@@ -127,6 +133,8 @@ func (s *GRPCServer) EvaluateExpr(expr hcl.Expression, opts sdk.EvaluateExprOpti
127133
case sdk.SelfModuleCtxType:
128134
runner = s.runner
129135
case sdk.RootModuleCtxType:
136+
s.mu.Lock()
137+
defer s.mu.Unlock()
130138
runner = s.rootRunner
131139
}
132140

0 commit comments

Comments
 (0)