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

Error: Premature close on DELETE requests after upgrading to 10.0.3 (from 9.6.0) #990

Closed
2 tasks done
rlr opened this issue Dec 12, 2019 · 16 comments · Fixed by #995
Closed
2 tasks done

Error: Premature close on DELETE requests after upgrading to 10.0.3 (from 9.6.0) #990

rlr opened this issue Dec 12, 2019 · 16 comments · Fixed by #995
Assignees
Labels
bug Something does not work as it should

Comments

@rlr
Copy link

rlr commented Dec 12, 2019

Describe the bug

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 7b2ccb0?

  • Node.js version: v12.13.1

Actual behavior

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

Expected behavior

We shouldn't get a Premature close error on successful DELETE requests.

Code to reproduce

  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,
  });

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

url, username, password and body are missing. Please update your code.

@rlr
Copy link
Author

rlr commented Dec 12, 2019

@szmarczak well, I cant provide those but I'll put in dummy values I guess

@rlr
Copy link
Author

rlr commented Dec 12, 2019

@szmarczak sorry, I had pasted the code for 9.6. Fixed now.

@szmarczak
Copy link
Collaborator

I cannot reproduce: https://runkit.com/szmarczak/5df28703ccf29c001cf54735

@rlr
Copy link
Author

rlr commented Dec 12, 2019

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.

@szmarczak
Copy link
Collaborator

Are you sure it's got@10.0.4?

@rlr
Copy link
Author

rlr commented Dec 12, 2019

@szmarczak I was on got@10.0.3 but I dont see anything in 10.0.4 that would affect it.

@szmarczak
Copy link
Collaborator

Are you doing this:

got.on('response', response => {
	response.on('error', ...);
});

Or just applying try/catch on the code provided above?

@szmarczak
Copy link
Collaborator

I see it's Error and not GotError, so is this an unhandled rejection / uncaught exception?

@szmarczak
Copy link
Collaborator

What are the response headers?

@rlr
Copy link
Author

rlr commented Dec 13, 2019

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.

@szmarczak
Copy link
Collaborator

I'm able to reproduce it now, will post a fix soon.

@szmarczak szmarczak added the bug Something does not work as it should label Dec 13, 2019
@szmarczak szmarczak self-assigned this Dec 13, 2019
@szmarczak
Copy link
Collaborator

if (!(isAborted() && error.message === 'Premature close')) {

If to remove the isAborted() check it works as expected.

@rlr
Copy link
Author

rlr commented Dec 13, 2019

@szmarczak great news. thanks for looking into it!

@rlr
Copy link
Author

rlr commented Jan 6, 2020

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

@rlr
Copy link
Author

rlr commented Jan 6, 2020

Filed #1014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants