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

Stream is not destroyed on error #25

Closed
szmarczak opened this issue May 3, 2020 · 5 comments · Fixed by #27
Closed

Stream is not destroyed on error #25

szmarczak opened this issue May 3, 2020 · 5 comments · Fixed by #27

Comments

@szmarczak
Copy link
Contributor

Instead, an error event is emitted:

stream.emit('error', error);

This causes getStream() to hang on Node.js 14.1.0.

@sindresorhus
Copy link
Owner

Which stream should be destroyed? I thought streams are automatically destroyed on error unless there's a handler.

@szmarczak
Copy link
Contributor Author

I thought streams are automatically destroyed on error unless there's a handler.

The thing is that there is a handler. If there's an error of any kind, Got tries to read the response. But since the stream is not destroyed, it just hangs on Node.js >= 14.0.0.

I'd just replace

decompress.on('error', error => {
// Ignore empty response
if (error.code === 'Z_BUF_ERROR') {
stream.end();
return;
}
stream.emit('error', error);
});
const finalStream = streamPipeline(response, decompress, stream, () => {});

with

	const finalStream = streamPipeline(response, decompress, stream, error => {
		if (error) {
			if (error.code === 'Z_BUF_ERROR') {
				stream.end();
				return;
			}

			stream.destroy(error);
		}
	});

@sindresorhus
Copy link
Owner

Sounds good. You know streams better than me.

@szmarczak
Copy link
Contributor Author

szmarczak commented May 3, 2020

Nah, I just randomly stumbled upon a Got issue and found a culprit :P But it doesn't hang on Node.js 13 so probably something has changed under the hood.

@szmarczak
Copy link
Contributor Author

I think it's either https://github.com/nodejs/node/pull/31182/files or https://github.com/nodejs/node/pull/32158/files or maybe both. But it's nice to see stream improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants