Skip to content

Commit

Permalink
add locks around stream send (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukclivecox authored May 23, 2022
1 parent 8074c29 commit 3e4f4e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scheduler/pkg/agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type SchedulerAgent interface {

type AgentSubscriber struct {
finished chan<- bool
//mutext sync.Mutex // grpc streams are not thread safe for sendMsg https://github.com/grpc/grpc-go/issues/2355
stream pb.AgentService_SubscribeServer
mutext sync.Mutex // grpc streams are not thread safe for sendMsg https://github.com/grpc/grpc-go/issues/2355
stream pb.AgentService_SubscribeServer
}

func NewAgentServer(
Expand Down Expand Up @@ -122,10 +122,12 @@ func (s *Server) Sync(modelName string) {
continue
}

as.mutext.Lock()
err = as.stream.Send(&pb.ModelOperationMessage{
Operation: pb.ModelOperationMessage_LOAD_MODEL,
ModelVersion: &pb.ModelVersion{Model: latestModel.GetModel(), Version: latestModel.GetVersion()},
})
as.mutext.Unlock()
if err != nil {
logger.WithError(err).Errorf("stream message send failed for model %s and replicaidx %d", modelName, replicaIdx)
continue
Expand All @@ -147,10 +149,12 @@ func (s *Server) Sync(modelName string) {
logger.Errorf("Failed to find server replica for %s:%d", modelVersion.Server(), replicaIdx)
continue
}
as.mutext.Lock()
err = as.stream.Send(&pb.ModelOperationMessage{
Operation: pb.ModelOperationMessage_UNLOAD_MODEL,
ModelVersion: &pb.ModelVersion{Model: modelVersion.GetModel(), Version: modelVersion.GetVersion()},
})
as.mutext.Unlock()
if err != nil {
logger.WithError(err).Errorf("stream message send failed for model %s and replicaidx %d", modelName, replicaIdx)
continue
Expand Down

0 comments on commit 3e4f4e1

Please sign in to comment.