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
callback called twice on error. #304
Comments
Can you provide a test case (preferred) or code snippet that demonstrates the behavior you are observing. Also, can you reference a version number? |
I just ran into the same issue. Here's the gist that demonstrates it. I'm using request v2.27.0 |
I'm experiencing this too. When a response times out, the callback is called twice--first with an err.code of ETIMEDOUT and then a second time with an err.code of ECONNRESET. This makes handling the errors really hard since the response processing logic gets run twice. I wrote a functional test to try to show this. It seems that the basic syntax for a request works fine and returns just ETIMEDOUT (test 1 below). But when using the syntax of req.on('response'), req.on('error'), etc for more custom handling, then the issue appears--i.e. the callback is called twice, first with ETIMEDOUT and then again with ECONNREST (test 2 below). To run the test below:
I think it has something to do with req.on('error') being called multiple times, but I'm not sure...
node v0.10.15 |
I found a solution (workaround?) so that the callback is only called once when an err of ETIMEDOUT occurs. Within req.on('error'), I added Now when I receive an ETIMEDOUT error, it's the only error received and the callback is only invoked once. I still have more testing of other request errors to do to determine if this causes others problems that I'm not aware of at the moment. But for now it gets me past the issue of ETIMEDOUT invoking the callback twice.
|
i think this is fixed. |
i still have it, do you mean fixed it with put req.abort() on error handling? |
I still get this on request 2.42. |
Hey guys, I think I tracked this down to the right place. File: request.js So based on @j20 work around I found that we are aborting the http/https request we make internally when a timeout happens. However we do not abort the actual Request instance like @j20 does. Any thoughts? |
Also whats the ideal way to fix this? Is there a use case for users to rely on the ECONNRESET error event? |
Okay to shed even more light on the subject, Disclaimer: Not pointing fingers - Just Time Traveling This is when the tests were changed to accommodate another change. That other change is. And it all gets tied together by some logic that looks like this.
Now that line above goes back probably to nearly to the beginning, i stopped checking after 0.3.6. |
All in all, given the history, this is a bug and I believe I fixed it. |
#1076 has been merged, closing. |
on making get request, if the request fails due to timeout callback is getting called twice.
The text was updated successfully, but these errors were encountered: