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.

Socket hang up on GET request with Auth header JWT

See original GitHub issue

Hey, i’m getting an error with a fairly simple GET request:

Error:  { Error: socket hang up
    at createHangUpError (_http_client.js:253:15)
    at Socket.socketOnEnd (_http_client.js:345:23)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9) code: 'ECONNRESET', response: undefined }

Any tips on how to resolve this? Do I need to config some socket things or something? I don’t understand if this is an issue with my code or perhaps some dependancy conflict. Everything i’ve tried doesn’t work 😦

Here is the test:

import superagent from 'superagent';
var request = superagent;

...

const USER_JWT_VALID = 'JWT asdf.....';

it('should work', (done) => {
  request
    .get('http://localhost:3000/api/something/private')
    .set('Accept', 'application/json')
    .set('Authorization', 'Bearer ' + USER_JWT_VALID)
    .end((err, res) => {
      console.log('Error: ', err);
      if (err) done(err);
      expect(res.body).to.be.an('object');
    });
});

my related packages:

"express": "^4.14.0",
"superagent": "^3.3.1",
"mocha": "^3.2.0",

node v7.3.0.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kornelskicommented, Dec 28, 2016

Socket hang up means the server closed the connection, which could be caused either by a hard crash of the server or a serious syntax error in the request.

So you see any errors on server side? Is it possible that you have some non-ASCII characters or unexpected newlines in your headers?

Try running nc -l 3000 instead of your server and see what superagent sends.

0reactions
ttbarnescommented, Dec 31, 2016

Sorry guys - this is nothing to do with superagent. This seems to be a bug with passport-jwt (auth GET requests are not getting past passport auth) Thanks all the same! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket hang up on GET request with Auth header JWT #1145
Socket hang up means the server closed the connection, which could be caused either by a hard crash of the server or a...
Read more >
Passport JWT auth in unit test - socket hang up - Stack Overflow
GET requests with the users's JWT in Authorization header work perfectly. It seems that the user being used for authentication, in the test ......
Read more >
502 Bad Gateway - Socket hang up | Apigee Edge
The error code [socket hang up][ECONNRESET] indicates that the target server has closed the connection with Edge Microgateway. This can be searched in...
Read more >
Socket hang up problems - Google Groups
Hi, I've been getting this issue every now and then on a long poll request. It doesn't happen consistently so I'm finding it...
Read more >
Middlewares | Socket.IO
A middleware function is a function that gets executed for every incoming connection.
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