Skip to content
Permalink
Browse files

fix(server): add workaround for possible broken pipe

  • Loading branch information...
mycoboco committed Jul 3, 2019
1 parent a98ddba commit 1a69b1286090922aad95e0900daff5667800c969
Showing with 6 additions and 2 deletions.
  1. +6 −2 server/lib/api.js
@@ -326,8 +326,12 @@ function song(req, res) {
})
rs = fs.createReadStream(songs[0].path)
}
res.on('error', function () { rs.close() })
.on('close', function () { rs.close() })
// workaround for broken pipe; old stream has no destroy()
res.on('unpipe', function () {
rs.once('readable', function () { rs.close() })
})
res.on('error', function () { rs.unpipe(res) })
.on('close', function () { rs.unpipe(res) })
rs.pipe(res)
})
})

0 comments on commit 1a69b12

Please sign in to comment.
You can’t perform that action at this time.