Primus authorize async action causing reconnecting loop
See original GitHub issueVersion:6.0.5
Environment:
- Operating system:Ubuntu 16.04 64bit
- Browser:react-native
- Node.js:v4.6.0
Note Sync version if authorize is working fine (all examples are using sync version)
Expected result: Authorization middleware waits for async action to complete and then calls connection event.
Actual result: Authorization middleware causing reconnecting loop in client. Client never gets connected.
Steps to reproduce:
//Server
function authorize(req, done) {
setTimeout(function() {
done(); //auth should succeed after 1s (async)
}, 1000);
};
var primus = new Primus(server.listener, {"pathname": "/connect"});
primus.authorize(authorize);
primus.on('connection', function(spark) {
//connection is called even authorization is still in progress
console.log('New primus connection');
});
primus.on('disconnection', function(spark) {
console.log('New primus disconnection');
//client is immediately disconnected after connect see server log and get stuck in loop of disconnect/connect
});
Server log
primus:transformer handling HTTP upgrade for url: /connect?access_token=6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a&_primuscb=LW5xPva
primus:transformer executing middleware (forwarded) synchronously
primus:transformer executing middleware (authorization) asynchronously
2016-10-27T11:36:51.284Z - info: Authorizing attempt token: 6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a
2016-10-27T11:36:51.304Z - debug: Authorization via token: 6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a is valid
primus:spark setting new heartbeat timeout for LW5xQbg
primus:spark transformer closed connection for LW5xQbg
primus:spark emitting final events for spark LW5xQbg
2016-10-27T11:36:51.308Z - info: New primus disconnection
2016-10-27T11:36:51.309Z - info: New primus connection
primus:spark releasing references from our spark object for LW5xQbg
primus:transformer handling HTTP upgrade for url: /connect?access_token=6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a&_primuscb=LW5xkOY
primus:transformer executing middleware (forwarded) synchronously
primus:transformer executing middleware (authorization) asynchronously
2016-10-27T11:38:15.183Z - info: Authorizing attempt token: 6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a
2016-10-27T11:38:15.200Z - debug: Authorization via token: 6d7001dbb305ff2f3e958a236c035f8d86271217e2298f70ff9f4a7c03455b0a is valid
primus:spark setting new heartbeat timeout for LW5xl4X
primus:spark transformer closed connection for LW5xl4X
primus:spark emitting final events for spark LW5xl4X
2016-10-27T11:38:15.204Z - info: New primus disconnection
2016-10-27T11:38:15.204Z - info: New primus connection
primus:spark releasing references from our spark object for LW5xl4X
Client log
[DEBUG] Primus outgoing::open
'[DEBUG] Primus reconnect', { 'reconnect timeout': 30000,
retries: 10,
factor: 2,
max: Infinity,
min: 500,
start: 1477568966756,
duration: 12778,
attempt: 4,
backoff: false,
scheduled: 6857 }
'[DEBUG] Primus reconnect scheduled', { 'reconnect timeout': 30000,
retries: 10,
factor: 2,
max: Infinity,
min: 500,
start: 1477568966756,
duration: 12778,
attempt: 5,
backoff: true,
scheduled: 15310 }
event reconnect and reconnect scheduled repeats until number of attempts is exhausted
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
engine.io reconnect loop after waking from sleep (Mac) · Issue #306 ...
I've managed to reproduce it once. The engine.io server triggered an Session id unknown 400 error on the client which seemed to have...
Read more >Elegant way of reconnecting loop with boost::asio?
I have a TCP client that should try to connect asynchronously to a server, if the connection fails because the server is offline...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok. I dived deeper. And I can only replicate with my setup. When I use primus server from examples, it’s working fine. Sorry for this. Will update when figure out, what is wrong with my code.
Actually I’m also wondering why it only messed the authentication middleware and kept rest working.