Skip to content
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

Misfire of the polling request #1261

Closed
lyi2012 opened this issue Aug 30, 2013 · 5 comments
Closed

Misfire of the polling request #1261

lyi2012 opened this issue Aug 30, 2013 · 5 comments
Labels

Comments

@lyi2012
Copy link

lyi2012 commented Aug 30, 2013

I am using Atmosphere 1.0.15. I build my application on top of the Jersey pub-sub sample using long-polling.
I noticed a tricky issue of miss fire of the polling request. I did some troubleshooting and noticed that from "jquery.atmosphere.js", the
function _reconnect(ajaxRequest, request, reconnectInterval);
has the following logic,

request.id = setTimeout(function() {
    _executeRequest(request);
}, reconnectInterval);

Under some conditions, it can be cancelled by clearTimeout() call unexpectedly, which cause the client stop polling.

@lyi2012
Copy link
Author

lyi2012 commented Aug 30, 2013

The clearTimeout() is from function _timeout().

@lyi2012
Copy link
Author

lyi2012 commented Aug 30, 2013

Hey, Jeanfrancois,

From my observation, I guess the root cause might be as the following.

When the polling request returns, it schedules the next poll using

setTimeout(function() {
_executeRequest(request);
}, 0);

Which is to fire the next polling request immediately after this polling returns. More specifically, after the current thread returns, since JS is single threaded by nature.
However, if the response of the sending request gets in before the next polling request is fired, it calls _timeout() and kills the next polling request.

This happens if incoming message interlays with the sending message. I guess the scheduling of the thread is not guaranteed even if we specifies it to timeout in 0 ms.

Let me know what you think.

Thanks!

@lyi2012
Copy link
Author

lyi2012 commented Aug 30, 2013

Hi, Jeanfrancois,

I setup a small application in which the client sends a message to itself.
The following is a copy of logs from my Chrome console, after I put some log lines into jquery.atmosphere.js. On the 4th last line, the clearTimeout kills the next polling request.

// My request
var ch = messagingAgent.subscribe('1');

ch.onMessage = function(message) {
console.log(message);
};

// Console outputs

readyState: 2 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 3 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 4 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
isAllowedToReconnect: true jquery.atmosphere.js:1606
rq.executeCallbackBeforeReconnect: false jquery.atmosphere.js:1607
reconnecting ... jquery.atmosphere.js:1610
before setTimeout for _executeRequest jquery.atmosphere.js:1712
before _executeRequest jquery.atmosphere.js:1714

// My request
ch.send(1, "1");

readyState: 2 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 4 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 2 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 3 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 4 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
isAllowedToReconnect: true jquery.atmosphere.js:1606
rq.executeCallbackBeforeReconnect: false jquery.atmosphere.js:1607
reconnecting ... jquery.atmosphere.js:1610
before setTimeout for _executeRequest jquery.atmosphere.js:1712
1
before _executeRequest jquery.atmosphere.js:1714

// My request
ch.send(1, "1");

// Console outputs
readyState: 2 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 3 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
readyState: 4 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
isAllowedToReconnect: true jquery.atmosphere.js:1606
rq.executeCallbackBeforeReconnect: false jquery.atmosphere.js:1607
reconnecting ... jquery.atmosphere.js:1610
before setTimeout for _executeRequest jquery.atmosphere.js:1712
1
readyState: 2 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222   // RECONNECT REQUEST IS KILLED HERE!
readyState: 4 jquery.atmosphere.js:1504
clearing timeout in _timeout() jquery.atmosphere.js:1222
clearing timeout in _clearState() jquery.atmosphere.js:2403

@jfarcand
Copy link
Member

jfarcand commented Sep 2, 2013

Hey, you need to try 1.0,16. I think this has been fixed. Pull the latest version from here and let me know.

@jfarcand jfarcand closed this as completed Sep 2, 2013
@jfarcand jfarcand reopened this Sep 2, 2013
@jfarcand
Copy link
Member

jfarcand commented Sep 3, 2013

OK I was never able to reproduce the issue, but pushed a fix here. Try this version it should now works.

@jfarcand jfarcand closed this as completed Sep 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants