-
Notifications
You must be signed in to change notification settings - Fork 14
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
Failure causes infinite loop #4
Comments
Whoops, good catch! I'll try to make a repeatable test case at some point... |
You’re a good man. BTW: I did successfully test this with: function emitErr(err) { And a different but related question: Scenario: using sox-stream and sox fails to transcode, how do I send a 500 http status code to the client? I’ve tried lazypipe() and other such interrupted or conditional methods.
|
If you pipe the output of sox-stream to your response, then if an error occurs during the transcoding process, then you will have already responded with part of the file. As far as I know, the headers are sent at the beginning of the response, so you can't start sending the file until it is finished transcoding. So you need to buffer the file to memory or disk: Memory version, var concat = require('simple-concat')
// ...
stream.pipe(convert).pipe(concat(function (err, buf) {
if (err) {
res.writeHead(500)
res.end()
} else {
res.writeHead(200)
res.end(buf)
}
})) Disk version: stream.pipe(fs.createWriteStream('herp_derp'))
.on('end', function () { // Or is it 'close'?
res.writeHead(200)
fs.createReadStream('herp_derp').pipe(res)
}).on('error', function (err) {
res.writeHead(500)
res.end()
}) If you use disk caching, maybe |
Thank you for this!
|
This line is causing an infinite loop.
The problem comes when a failure condition is created for example when being sent an mp3 file and telling sox it’s a wav file. (Aside from that being a bad thing, the module must handle it gracefully.)
Sox throws an error as it should.
The tmpFile does not exist so cleanup throws an error and you’re in an infinite loop.
The suggested way to deal with it is in this style, but forgive me for not knowing how to take the above line and implement it like the below line.
function emitErr(err) {
if (err.code !== 'ENOENT') { // Avoid infinite loops
tmpFile.cleanup(duplex.emit.bind(duplex, 'error', err));
}
}
The text was updated successfully, but these errors were encountered: