Skip to content

Commit f3d8a55

Browse files
committed
Fix data race in OnTrafficFromServer by cloning resp before channel send
The same v1.Struct pointer was sent to UpdateCacheChannel and returned to GatewayD via gRPC. The UpdateCache goroutine mutated Fields while gRPC serialized them concurrently, corrupting responses under load.
1 parent 0611dcb commit f3d8a55

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

plugin/plugin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
goRedis "github.com/redis/go-redis/v9"
1818
"github.com/spf13/cast"
1919
"google.golang.org/grpc"
20+
"google.golang.org/protobuf/proto"
2021
)
2122

2223
type Plugin struct {
@@ -296,7 +297,7 @@ func (p *Plugin) OnTrafficFromServer(
296297
_ context.Context, resp *v1.Struct,
297298
) (*v1.Struct, error) {
298299
p.Logger.Debug("Traffic is coming from the server side")
299-
p.UpdateCacheChannel <- resp
300+
p.UpdateCacheChannel <- proto.Clone(resp).(*v1.Struct)
300301
return resp, nil
301302
}
302303

0 commit comments

Comments
 (0)