-
Notifications
You must be signed in to change notification settings - Fork 343
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
Implement Request.signal to detect client disconnects #3488
base: main
Are you sure you want to change the base?
Conversation
In #3033 I made an observation which I don't think has been covered here.
|
3afd1ad
to
9088343
Compare
It looks like you force-pushed changes in response to review comments and a rebase at the same time. Unfortunately this means we reviewers are unable to see what changed since we last reviewed. Could you please rebase this back to e5b3760 so that we can directly diff against 3afd1ad? If you need to rebase forward to fix merge conflicts, please do it as a second push, and write a comment in between, so that GitHub doesn't collapse them. (GitHub is, unfortunately, extremely annoying in this regard...) |
ae43332
to
4ad11a3
Compare
@kentonv Sorry for making a mess out of the diff. I'll be more careful about this next time. |
4ad11a3
to
d43950e
Compare
Still need to address the passthrough issue? (The big blockquote in my earlier comment.) |
Yes, still to address:
|
@@ -0,0 +1,128 @@ | |||
import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers'; | |||
import assert from 'node:assert'; | |||
import { scheduler } from 'node:timers/promises'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, scheduler.wait
is actually available without node compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VSCode just helpfully keeps importing it. I'll get rid of it before I merge.
d977e53
to
3651ba7
Compare
The latest push takes care of the passthrough subrequest case. |
return jsg::alloc<Request>(method, url, redirect, kj::mv(headersClone), getFetcher(), getSignal(), | ||
kj::mv(cfClone), kj::mv(bodyClone)); | ||
return jsg::alloc<Request>(method, url, redirect, kj::mv(headersClone), getFetcher(), | ||
/* signal */ getThisSignal(), kj::mv(cfClone), kj::mv(bodyClone), /* thisSignal */ kj::none); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm treating req.clone()
and new Request(req)
differently in that former always clones the associated signal, while the latter will respect ignoreForSubrequests
and ignore the signal of the incoming fetch. Let me know if that doesn't sound right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is not the solution I was expecting. I thought that the implementation of fetch()
would be modified to ignore the signal if it came from the original top-level request. Why should cloning the request (whether via .clone()
or the constructor) drop the signal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if someone just does fetch(originalRequest)
, the request is not cloned at all, so doesn't this not even solve that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does work because fetch calls the Request constructor again, but yeah this isn't the right way to accomplish this. I fixed it.
3651ba7
to
2d76a37
Compare
How it works:
Request.signal
.