-
Notifications
You must be signed in to change notification settings - Fork 327
Description
There seems to be a bug in the go code generation that leads to context updates in Error
server hooks failing to reach the ResponseSent
hook.
twirp/example/service.twirp.go
Lines 273 to 278 in 987a500
if n, err := resp.Write(respBytes); err != nil { | |
msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) | |
twerr := twirp.NewError(twirp.Unknown, msg) | |
callError(ctx, s.hooks, twerr) | |
} | |
callResponseSent(ctx, s.hooks) |
callError
on line 276 returns a new context, which is ignored, rather than overriding ctx
.
This behavior is critical for finishing spans correctly in the twirp/datadog integration. In general, this behavior is critical any time the error hook wants to pass state down to the response sent callback.
Edit: This bug only manifests in a rare edge case, when writing the response fails. Normal application errors go through writeError
in the generated code, which does update ctx
correctly based on callError
before calling callResponseSent
.