Skip to content

Commit d596330

Browse files
authored
RSDK-6985 - Filter out SetHeader errors (viamrobotics#4338)
1 parent 55ac5e3 commit d596330

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

operation/web.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ func (m *Manager) UnaryServerInterceptor(
5656
ctx, done := m.CreateFromIncomingContext(ctx, info.FullMethod)
5757
defer done()
5858
if op := Get(ctx); op != nil && op.ID.String() != "" {
59-
utils.UncheckedError(grpc.SetHeader(ctx, metadata.MD{opidMetadataKey: []string{op.ID.String()}}))
59+
// SetHeader will occasionally error because of a data race if the request has been cancelled from client side.
60+
// The cancel signal (RST_STREAM) is processed on a separate goroutine and will close the existing gRPC stream,
61+
// which will end up writing headers and returning a message to the server. If headers were sent before SetHeader
62+
// is called here, SetHeader will error.
63+
// Since the behavior is expected and part of the gRPC stream closing, only log the error if it is unexpected
64+
// (the context error is nil, meaning request wasn't cancelled).
65+
if err := grpc.SetHeader(ctx, metadata.MD{opidMetadataKey: []string{op.ID.String()}}); err != nil &&
66+
ctx.Err() == nil {
67+
m.logger.CDebugw(ctx, "error while setting header", "err", err)
68+
}
6069
}
6170
return handler(ctx, req)
6271
}

0 commit comments

Comments
 (0)