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

On ECONNRESET, assert() calls undefined res.status which throws an error #258

Closed
kadishmal opened this issue Jul 14, 2015 · 9 comments
Closed

Comments

@kadishmal
Copy link

When for some reason the remote server fails and the connection is reset, supertest cannot handle the error properly which is why the following error is thrown:

|"TypeError: Cannot read property 'status' of undefined",
|"    at Test.assert (/webapp/node_modules/supertest/lib/test.js:203:12)",
|"    at assert (/webapp/node_modules/supertest/lib/test.js:132:12)",
|"    at /webapp/node_modules/supertest/lib/test.js:129:5",
|"    at Test.Request.callback (/webapp/node_modules/superagent/lib/node/index.js:781:12)",
|"    at ClientRequest.<anonymous> (/webapp/node_modules/superagent/lib/node/index.js:736:10)",
|"    at ClientRequest.emit (events.js:95:17)",
|"    at Socket.socketOnEnd [as onend] (http.js:1569:9)",
|"    at Socket.g (events.js:180:16)",
|"    at Socket.emit (events.js:117:20)",
|"    at _stream_readable.js:944:16",
|"    at process._tickCallback (node.js:448:13)"

There is this code on line 202 in supertest/lib/test.js:

if (status) {
  if (res.status !== status) {
    var a = http.STATUS_CODES[status];
    var b = http.STATUS_CODES[res.status];
    return fn(new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"'), res);
  }

  // remove expected superagent error
  if (resError && resError instanceof Error && resError.status === status) {
    resError = null;
  }
}

On the line 203, which says if (res.status !== status) {, res is undefined. Because resError = { [Error: socket hang up] code: 'ECONNRESET', response: undefined }.

@RomanSchmidtAppinio
Copy link

Same here. During a stress test mongoose connection limit is reached and node is sending an empty result. So i get same exception.

My temporary Solution:

Test.prototype.assert = function(resError, res, fn){
if(!res) {
res = {
status: 'FOOO'
};
}

mmerkes added a commit to mmerkes/supertest that referenced this issue Jul 20, 2015
@mikelax
Copy link
Contributor

mikelax commented Jul 22, 2015

This is a duplicate of #237. There is PR #258 to address this.

@mikelax mikelax closed this as completed Jul 22, 2015
mikelax added a commit that referenced this issue Sep 17, 2015
Fixes #258, handles undefined Response object rather than throwing an…
@kadishmal
Copy link
Author

#260 doesn't fix this issue. In fact #260 doesn't include any code change except in the test case. Need to reopen.

@mleanos
Copy link

mleanos commented Oct 29, 2015

I'm having this issue as well on Windows 7. I've described my experiences with this issue here #230

mleanos added a commit to mleanos/mean that referenced this issue Oct 29, 2015
Removes a duplicate User CRUD test for Profile Picture.

There are two reasons for this commit.

1) Duplicate of
https://github.com/meanjs/mean/blob/master/modules/users/tests/server/user.server.routes.tests.js#L833-L848
2) This test is problematic in Windows environment.
Related to:
ladjs/supertest#230
ladjs/supertest#258

The latter may be an issue with the `.attach` method not completely
loading the file into memory before the 400 status response is sent back
due to no User logged in.
@varunj90
Copy link

@kadishmal , @mleanos - any resolution to this?

#298

if you could help me with 298 . thanks !

@kadishmal
Copy link
Author

No, this particular issue is still present. res.status is not handled properly because res is undefined.

@varunj90
Copy link

@kadishmal - thanks for the update. Do you know ETA for this fix; or know if supertest is working towards a fix?

My issue is similar to this : #298

@varunj90
Copy link

@mikelax - Do you know ETA for this fix; or know if supertest is working towards a fix?

My issue is similar to this : #298

@aides
Copy link

aides commented Aug 29, 2016

It's quite an old thread and it is closed, but I still encounter this issue. It is reproduced on Windows only and when I send a PUT with binary content with content-type set to a different value.
After googling this is still the most relevant place, so maybe someone knows how to address this problem?

kgrossnickle pushed a commit to cen3031-5a/trainerScheduling that referenced this issue Oct 10, 2017
Removes a duplicate User CRUD test for Profile Picture.

There are two reasons for this commit.

1) Duplicate of
https://github.com/meanjs/mean/blob/master/modules/users/tests/server/user.server.routes.tests.js#L833-L848
2) This test is problematic in Windows environment.
Related to:
ladjs/supertest#230
ladjs/supertest#258

The latter may be an issue with the `.attach` method not completely
loading the file into memory before the 400 status response is sent back
due to no User logged in.
lupinthethirdgentleman pushed a commit to lupinthethirdgentleman/mean-dashboard that referenced this issue Aug 5, 2021
Removes a duplicate User CRUD test for Profile Picture.

There are two reasons for this commit.

1) Duplicate of
https://github.com/meanjs/mean/blob/master/modules/users/tests/server/user.server.routes.tests.js#L833-L848
2) This test is problematic in Windows environment.
Related to:
ladjs/supertest#230
ladjs/supertest#258

The latter may be an issue with the `.attach` method not completely
loading the file into memory before the 400 status response is sent back
due to no User logged in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants