question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Primus authorize async action causing reconnecting loop

See original GitHub issue

Version: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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mauron85commented, Oct 27, 2016

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.

0reactions
mauron85commented, Oct 28, 2016

Actually I’m also wondering why it only messed the authentication middleware and kept rest working.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found