We updated from 9.6.0 to 10.0.3 and as soon as it was deployed, we started getting Error: Premature close on most or all of our DELETE requests. The GET and POST requests work fine.
Maybe some cases were missed in 7b2ccb0d69fca9aba27373ab344f97d389d692f2?
Error: Premature close
File "internal/streams/end-of-stream.js", line 61, col 15, in IncomingMessage.onclose
File "events.js", line 210, col 5, in IncomingMessage.emit
File "domain.js", line 498, col 23, in IncomingMessage.EventEmitter.emit
File "/home/node/guardian-website/node_modules/@szmarczak/http-timer/dist/index.js", line 40, col 20, in IncomingMessage.origin.emit
return emit(event, ...args);
File "_http_client.js", line 363, col 11, in TLSSocket.socketCloseListener
File "events.js", line 215, col 7, in TLSSocket.emit
File "domain.js", line 498, col 23, in TLSSocket.EventEmitter.emit
File "net.js", line 659, col 12, in null.<anonymous>
File "_tls_wrap.js", line 481, col 7, in TCP.done
We shouldn't get a Premature close error on successful DELETE requests.
const url = "https://example.com";
const username = "username";
const password = "password";
const body = undefined;
const resp = await got(url, {
username,
password,
method: "DELETE",
throwHttpErrors: false,
responseType: "json",
json: body ? body : undefined,
});
url, username, password and body are missing. Please update your code.
@szmarczak well, I cant provide those but I'll put in dummy values I guess
@szmarczak sorry, I had pasted the code for 9.6. Fixed now.
I cannot reproduce: https://runkit.com/szmarczak/5df28703ccf29c001cf54735
Yeah, it wont work with those variables. We'll need to find a url we can use to test.
Also, I am unable to reproduce locally on my machine (OS-X). But I see the errors as soon as I deploy to our servers.
Are you sure it's [email protected]?
@szmarczak I was on [email protected] but I dont see anything in 10.0.4 that would affect it.
Are you doing this:
got.on('response', response => {
response.on('error', ...);
});
Or just applying try/catch on the code provided above?
I see it's Error and not GotError, so is this an unhandled rejection / uncaught exception?
What are the response headers?
Unfortunately, this only happens on production servers and I dont have access to the headers. I haven't been able to reproduce locally or on heroku yet.
I'm able to reproduce it now, will post a fix soon.
If to remove the isAborted() check it works as expected.
@szmarczak great news. thanks for looking into it!
I just tried the latest version 10.2.1. I am still getting errors:
ReadError: premature close
File "/home/node/guardian-website/node_modules/got/dist/source/as-promise.js", line 48, col 27, in EventEmitter.<anonymous>
emitError(new errors_1.ReadError(error, options));
File "internal/process/task_queues.js", line 93, col 5, in processTicksAndRejections
File "/home/node/guardian-website/node_modules/end-of-stream/index.js", line 53, col 86, in onclosenexttick
if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
File "internal/process/task_queues.js", line 75, col 11, in processTicksAndRejections
Filed #1014