File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,16 @@ func (m *Manager) UnaryServerInterceptor(
56
56
ctx , done := m .CreateFromIncomingContext (ctx , info .FullMethod )
57
57
defer done ()
58
58
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
+ }
60
69
}
61
70
return handler (ctx , req )
62
71
}
You can’t perform that action at this time.
0 commit comments