-
-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Server side aborted request with Transfer-Encoding: chunked never resolve/reject #1096
Comments
This problem still occurs with node 13.11.0, so I tried to investigate this. It seems the issue is caused by this catch: Lines 29 to 36 in 62b3388
This change relates to #990. If the catch is deleted, then the premature close is thrown but... only with node v13.11.0+ ! I've tried this with node v13.9.0 (without the auto destroy on pipelines, introduced in node v13.10.0) and no error is thrown. To be compatible with node before v13.11.0, you need to add this before line 29: response.once('aborted', () => {
progressStream.destroy();
}); |
Can you try the latest v12 Node.js version? |
Sure. Result with node v12.16.1 is different as error thrown by the pipeline has an undefined code, and so, the catch can throw the error. The got promise then rejects but with a different error of the one from node v13 branch (where |
I've tested with an older v12 release too (v12.9.0) and the result is different comparing to v13 branch or latest v12. With the base got code, the got promise resolves with data sent before abortion. So we have a potentially truncated result but we don't have any information of this. |
Fwiw, I just stumbled upon this issue and I can reproduce it in both v13.6.0 and v13.12.0. |
Tested on master (merged #1051 so many bugs got fixed) and it gives me:
Please let me know if it's fixed on your side too or not. |
I just tried the v11 beta. Seems to be working for me now 👍 |
It should not be handled by timeouts and throws a timeout error, even if promises now resolve/reject or streams emit error event with got v11 (that is a good thing) because it's not a timeout. If timeouts are set at an upper value, say a minute as an example, the error will not be caught and transmitted until. In got v11 it should be there: Lines 962 to 969 in bf0b0cd
You have to add an additional listener on this like: response.on('aborted', () => {
// there is no error with this event, so create one
// (it should be improved to have a specific error with an error code, etc...)
const error = new Error('Request abort');
this._beforeError(new ReadError(error, options, response as Response));
}); With that, the output is:
which is better, doesn't depends on timeouts settings and is handleable by applications. |
Maybe these node's github issues can help to understand this problem: |
Another node's github issue, they tried to handle this correctly but failed: nodejs/node#28677 |
@rarkins #1062 (comment) seems to be related with this I think |
I don't know if this is the same problem as there is no ECONNRESET error here. The problem is really between got and node's http lib. Node's IncomingMessage can emit three different events to say no more Got v11 listen only two of these, Got v10 used I can't remind how it worked internally in got v9, but I pretty sure this version was not hanging on |
Timeouts can cause ECONNRESET. |
not anymore (wait for a release) |
There has been no workaround like this. You're confused. |
It still had that bug. Since Got v8 (when I joined Got). |
I think you're talking about the |
Yes it's pure speculation, but I'm pretty sure node's pipelines handle this problem. Maybe not directly by listening the
I'm really sure too for got v9: there's no hang related to this issue, my code and tests have been written with got v9. I have done some code to workaround this problem when I migrated to got v10. The major difference is got v9 resolves the promise or ends the stream without error and with a truncated response where got v10 simply hang. But It's possible too there's node's updates caused behaviour changes, as they done quasi-breaking changes on these modules the last weeks... |
Then I'm almost sure it was caused by the
The bug was still present, it just was failing silently: |
It occurs when the socket is closed without emitting a response event. |
I can confirm with the brand new got v11, an error is thrown/emitted on server abort after response cases in http 1.x context. Good job @szmarczak and thank you! |
If you see any bug, make an issue stright away! I've fixed two already and I'm going to release |
fwiw I landed on this issue when I encountered a resolved, chunked, response - it took some time to isolate that the transfer-encoding was the culprit because I just received a blank body. This was on Node 14.0. When I switched to Node 12.17 given the issues noted above it works as I would have expected. The promise resolves with the fully downloaded response. I upgraded from 14.0 to the 14.5 minor and re-ran my little test and it works as expected. lol node. I anticipate others may experience similar confusion on Node for Node 14 <= 14.5. Hoping I can save someone an hour or two trying to track that one down if they happen to stumble across this issue. |
In fact, I think your problem is related to this issue: #1295 which is a node 14 fixed issue. |
agreed. Thank you @darksabrefr |
A server side aborted request with
Transfer-Encoding: chunked
header conduces got to never resolve nor reject. I think got doesn't listenaborted
event fromIncomingMessage
. The stream version of got is affected too and stream never emitend
,abort
orerror
but stays in a stale state.This only outputs
server close
but no client response because the got promise never resolves nor rejects even with timeouts set.IncomingMessage
doesn't emitend
event in this case (at least in the latest node version, maybe this affirmation was not true in past versions, see: nodejs/node#25081, from where the examples here are derived) but anaborted
event. To show it, you can do that:Here, you can see a more precise output:
Note there's no client
end
event but anaborted
one. I have also included two statuses properties fromIncomingMessage
:complete
(true after anend
) andaborted
(true after anaborted
event)Checklist
The text was updated successfully, but these errors were encountered: