-
Notifications
You must be signed in to change notification settings - Fork 20
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
fix(comlink): ensure nodes always accept handshake synchronize events #2163
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -260,8 +260,7 @@ export const createController = (input: {targetOrigin: string}): Controller => { | |||
|
|||
const stop = () => { | |||
channels.forEach((channel) => { | |||
channel.disconnect() | |||
channel.stop() | |||
cleanupChannel(channel as unknown as Channel<Message, Message>) |
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.
Will the following also work?
cleanupChannel(channel as unknown as Channel<Message, Message>) | |
cleanupChannel(channel) |
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.
Unfortunately not as it stands, I guess this has to do with type variance? channel
here is of type Channel<R, S>
, and that isn't considered a subtype of Channel<Message, Message>
even if R
and S
extend Message
...or something like that.
I need to look at improving the typing in places, if you have any suggestions they'd be very welcome! 😊
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.
Great catch! :O 💖
Currently, comlink's node state machine will only handle syn handshake events when in an
idle
state. In some situations, the controller or some of the channels it maintains may detect a loss of connection and transition to ahandshaking
state, the disconnect event emitted at this point may then fail to reach the relevant node(s), and thus the node will remain in aconnected
state, as the nodes themselves only blindly respond to heartbeat events.This PR adds a change so that the node state machine will always transition to its internal
handshaking
state when receiving a syn handshake event, regardless of the state it is currently in. This should greatly improve the success rate of attempt reconnects. For example you may have noticed in our test environments that the connection is often lost after a HMR, this should no longer be the case.It also drops the default expected response timeout to 3s from 10s for requests for all requests that expect a response except for those initiated with
.fetch
(which remains at 10s).