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

Pipe through closed stream #545

Closed
StarpTech opened this issue Aug 4, 2018 · 1 comment
Closed

Pipe through closed stream #545

StarpTech opened this issue Aug 4, 2018 · 1 comment
Labels
question The issue is a question about Got

Comments

@StarpTech
Copy link

StarpTech commented Aug 4, 2018

Hi,
in Got 8 I could pipe through a closed stream. In Got 9 I get this error:

Failed to pipe. The response has been emitted already.

to fix this I have to remove the await PEvent(response, 'response') event of the first stream:

Reproducible:

    const response = await this.httpClient.get(url, {
      stream: true
    })
   await PEvent(response, 'response')
   const stream = stream.pipe(response2)
   await PEvent(stream, 'response')

Solution:

    const response = await this.httpClient.get(sub.topic, {
      stream: true
    })
   // await PEvent(response, 'response')
   const stream = stream.pipe(response2)
   await PEvent(stream, 'response')

Does the new behaviour fix a bug or is it best-practice? At least we should add it to the release notes as breaking-change.

@szmarczak szmarczak added the question The issue is a question about Got label Aug 4, 2018
@szmarczak
Copy link
Collaborator

Does the new behaviour fix a bug or is it best-practice?

It's best practice to avoid bugs. See #223.

We could emit the error after the stream.Readable's end event, but there's a chance you'll get only a piece of the response (e.g. flowing mode is on), and we don't want that when we are piping it to a HTTP response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a question about Got
Projects
None yet
Development

No branches or pull requests

2 participants