Conversation
|
@danlapid @jasnell any questions/concerns here? Based on Sentry reporting this should address the issue at hand here – fetch spans are sometimes being reported after the outcome event, likely when the span only wraps up after a worker invocation has returned (I tried to cause this in a test using ctx.waitUntil(), but couldn't actually reproduce it). I think this is best addressed by deferring outcome event reporting. |
|
Can't say I believe in or like this change. |
Kindly note that the WorkerTracer already outlives the IoContext (or rather all events that can be reported from it) since IoContext_IncomingRequest owns WorkerTracer. (Otherwise we would not be able to print the warning in question here, which is reported within WorkerTracer). |
Sounds like changing it so the IoContext destructor tells the WorkerTracer to report the outcome event would be simple then. Let's go with that. |
Based on local testing, I believe this can't work as intended: In the common case, the IoContext/IoContext_IncomingRequest shuts down before metrics get reported (at least in workerd). The WorkerTracer is still being kept alive based on being co-owned by the RequestObserver though, and the outcome gets reported when the RequestObserver shuts down (right before WorkerTracer is deallocated). In this case we can't dispatch the outcome event when the IoContext shuts down because it is simply not available yet. |
I understand that this PR seems like a simple fix to you that addresses the immediate need but this comment just proves how convoluted the request lifecycle is. |
I'm not aware of the outcome changing after the IoContext shuts down here, or that it would need to be supported. What I see happening is that the order in which RequestObserver and IoContext shut down is not fixed, which puts us into this position. Do you think that needs to be changed so that the RequestObserver destructs first? Based on a brief look on the internal and workerd implementations, it looks to me like the outcome in RequestObserver is being set by RequestObserver::reportFailure, RequestObserver::setOutcome and when checking the return value of invoking a (custom)event. To me it looks like the issue with when outcome is reported is inherent in this design and hard to avoid, please let me know if you can think of a workaround/new approach. |
|
Ok looked together. |
cafc206 to
ae1ef21
Compare
This should address the 'reported tail stream event after stream close' warnings seen in testing.
ae1ef21 to
829156e
Compare
|
The generated output of |
This should address the 'reported tail stream event after stream close' warnings seen in testing.