-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition w/ body cancel #2009
Comments
ethanresnick
changed the title
Race condition w/ body cancel, and strange mixing results
Race condition w/ body cancel
Mar 16, 2023
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Description
Calling response.body.cancel — but only with a reason message — can lead to controller already closed errors.
Reproducible By
Expected Behavior
HTTPBin returns a 405 with an HTML body for this request. Calling
resp.body.cancel(reasonString)
should not error.Logs & Screenshots
About 80% of the time, the code above gives the following (uncaught) rejection:
It seems like there might be some sort of race condition.
Interestingly, if the code calls
resp.body.cancel()
(i.e., leaving the reason string out), the code never seems to throw. I think it may be that, somehow, the string passed to.cancel()
is propagated to here, where it fails theisErrorLike
check... or at least that would be consistent with this earlier bug: #1564Perhaps, rather than solely relying on an
isErrorLike
check on thebytes
, it'd be good to set a flag if this line was reached, and check ifisErrorLIike(bytes) || hitCatchFlag
.Environment
MacOS 13.2
Nodejs 19.6.0
undici 5.21.0
Additional context
In our code, we call other origins sometimes (i.e., not HTTPBin) and discard the body, and this issue doesn't seem to occur, so there may be some weird interaction going on between undici and httpbin. For example, the following code will never throw, even though this origin also returns 405 (with a plaintext body):
The text was updated successfully, but these errors were encountered: