-
Notifications
You must be signed in to change notification settings - Fork 356
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 when polling and upgrading #18
Comments
One thing we could do is have polling send a |
It also occurred to me that an elegant way to handle this is to fire events on the current transport when another potential upgrade transport connects. |
I am still not able to consistently reproduce this behavior. We were able to fix this by having the server send a ping packet after a successful probe was received. Obviously, this is not The Right Way to do things, but it helps to close an opening poll transport in a reasonable amount of time. You can find the changes for this in my branch (I didnt request a pull because I hope somebody will provide a better solution for this) |
What do you think about sending a noop packet to the open transport after a probe connection is established? |
I am not sure if this is the right approach: To give a context, I am posting a part of the maybeUpgrade function of the engine.io server. Please note the 'PLACEHOLDER' comment Socket.prototype.maybeUpgrade = function (transport) {
// [...]
var self = this;
function onPacket (packet) {
if ('ping' == packet.type && 'probe' == packet.data) {
transport.send([{ type: 'pong', data: 'probe' }]);
/* PLACEHOLDER */
} else if ('upgrade' == packet.type) {
// [...]
} else {
transport.close();
}
}
transport.on('packet', onPacket);
}; At first, I thought the issue could be solved be directly sending some information on the 'not-probed' transport. Same thing goes for I "resolved" the issue by changing the ping function to accept also a custom pingInterval. Everything in the range from 500ms to 2000ms works consistently. But, as I said before, I doubt that specific time-based intervals are a good approach for this. Maybe some kind of serialization would help on the client though? Something like "probe only when a poll connection is established", so it is guaranteed there is a poll connection going to the server, that can then be closed? Only thinking aloud here though, but I'd love to see some good ideas we could try to implement. |
The key is to queue the packet on the |
Fixed in engine.io |
if there is an ongoing polling request and the client is not receiving any data, the upgrade blocks until the client gets a response on the poll, usually a
ping
packet. this makes the usage of websockets difficult, if the server is not continously sending messages.this behavior can be observed more often if connecting to a remote server; it almost never happens if connecting via localhost in my tests.
tracebacks:
first part:
(after 20 seconds)
The text was updated successfully, but these errors were encountered: