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

Flowing issues when piping to a http response #78

Open
LinusU opened this issue Sep 12, 2017 · 4 comments
Open

Flowing issues when piping to a http response #78

LinusU opened this issue Sep 12, 2017 · 4 comments

Comments

@LinusU
Copy link
Collaborator

LinusU commented Sep 12, 2017

For some reason the stream cuts out after just a few kilobytes, it seems like something is wrong with flowing/paused mode and back pressure buffering... just guessing here...

Minimal test case:

const LineIn = require('line-in')
const Lame = require('lame')
const http = require('http')

http.createServer((req, res) => {
  const input = new LineIn()
  const encoder = new Lame.Encoder()

  res.writeHead(200, { 'Content-Type': 'audio/mp3' })

  input.pipe(encoder).pipe(res)
}).listen(4001, () => {
  console.log('http://localhost:4001/')
})

The behaviour could then be observed with e.g. curl:

$ curl localhost:4001 > test.mp3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9113    0  9113    0     0   1904      0 --:--:--  0:00:04 --:--:--  1904^C

Here it hanged after receiving 9113 bytes.

For some strange reason the following code works:

  // ...

  input.pipe(encoder) // .pipe(res)

  setInterval(() => encoder.resume(), 1000)
  encoder.on('data', (data) => res.write(data))

@TooTallNate if you have any ideas that would be greatly appreciated! If you have time, would you mind just trying to run this on your computer and see if it works?

@LinusU
Copy link
Collaborator Author

LinusU commented Sep 12, 2017

I should also not that piping to a fs.createWriteStream('test.mp3') works perfectly 🤔

@mikealeonetti
Copy link

Having the same issue where it hangs for a bit when encoding and then after an arbitrary amount of time it resumes and flushes. For me it happens right before flush. It randomly will decide to either flush immediately or wait about a minute or so and then flush.

Is this basically the issue you're having?

@LinusU
Copy link
Collaborator Author

LinusU commented Sep 21, 2017

Oh, actually, I never tried waiting more than a few seconds, will do that and see if it starts pushing data again...

@mikealeonetti
Copy link

I can confirm that your

setInterval(() => encoder.resume(), 1000)

Works as a workaround. It works for me, too! Both decoding and encoding. What is the issue that it gets clogged?

I'm using node v6.9.4 on Gentoo and v6.10.2 on Ubuntu and the problem happens on both.

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

No branches or pull requests

2 participants