Skip to content

Commit

Permalink
RSDK-6985 - Filter out SetHeader errors (viamrobotics#4338)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheukt committed Sep 3, 2024
1 parent 55ac5e3 commit d596330
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion operation/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ func (m *Manager) UnaryServerInterceptor(
ctx, done := m.CreateFromIncomingContext(ctx, info.FullMethod)
defer done()
if op := Get(ctx); op != nil && op.ID.String() != "" {
utils.UncheckedError(grpc.SetHeader(ctx, metadata.MD{opidMetadataKey: []string{op.ID.String()}}))
// SetHeader will occasionally error because of a data race if the request has been cancelled from client side.
// The cancel signal (RST_STREAM) is processed on a separate goroutine and will close the existing gRPC stream,
// which will end up writing headers and returning a message to the server. If headers were sent before SetHeader
// is called here, SetHeader will error.
// Since the behavior is expected and part of the gRPC stream closing, only log the error if it is unexpected
// (the context error is nil, meaning request wasn't cancelled).
if err := grpc.SetHeader(ctx, metadata.MD{opidMetadataKey: []string{op.ID.String()}}); err != nil &&
ctx.Err() == nil {
m.logger.CDebugw(ctx, "error while setting header", "err", err)
}
}
return handler(ctx, req)
}
Expand Down

0 comments on commit d596330

Please sign in to comment.