Skip to content

Commit f510872

Browse files
authored
Merge pull request #141 from dmcgowan/fix-events-deadlock
Fix deadlock in events forwarding when connection closes
2 parents 479c9b8 + b7f309a commit f510872

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/shim/task/service.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,17 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
232232
if err != nil {
233233
return nil, errgrpc.ToGRPC(err)
234234
}
235-
// Start forwarding events
236-
sc, err := vmevents.NewTTRPCEventsClient(vmc).Stream(ctx, empty)
235+
236+
// Start forwarding events.
237+
// Use the shim's long-lived context (not the RPC ctx) for the event
238+
// stream. If the connection closes, ctx gets canceled, which causes
239+
// RecvMsg to return without deleting the underlying ttrpc stream. The VM
240+
// keeps sending events to that orphaned stream, which fills the stream's
241+
// recv buffer and blocks the ttrpc receive loop — deadlocking all
242+
// subsequent calls on the same ttrpc client. This needs a fix in ttrpc
243+
// to avoid deadlock, but the stream should be consumed until the stream
244+
// is done or the ttrpc connection closes.
245+
sc, err := vmevents.NewTTRPCEventsClient(vmc).Stream(s.context, empty)
237246
if err != nil {
238247
return nil, errgrpc.ToGRPC(err)
239248
}

0 commit comments

Comments
 (0)