-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Got premature close error when using pump #711
Comments
thanks for report @Congelli501 ! Have you tried to investigate what could cause that? In the future for promise version we'll likely prefer async iterators to stream, with api similar to something like this: for await (const row of conn.queryRows(sql)) {
console.log(row);
} |
The problem is caused by the 'close' event being emitted before the 'end' event. |
The 'end' event (emitted by `stream.push(null)`) should always be emitted before the close event. This fixes issue sidorares#711
Fix issue #711: close emitted before end
@Congelli501 @sidorares Sorry to bring this up again, but I think I hit the same issue. Using Wrapping Shall I open a new issue instead? |
@sidorares any news on this issue? We're using node 18 and getting the |
Try upgrade mysql2 latest version. It work for me. |
If you don't know about it, pump is a module to better handle stream pipe (better error handling and better close handling to prevent resource leak) https://www.npmjs.com/package/pump.
It is considered by many as safer than pipe and may be part of node core in the future (nodejs/node#13506).
mysql2 streams are not working well with pump: a "premature close" error is thrown at the end of the stream.
Here is an example code to reproduce the error:
You can uncomment the "working" code (and comment the "not working" code) to use the working pipe version.
The text was updated successfully, but these errors were encountered: