Question: when not to use `pump`?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 917
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
Consider this example.
As soon as stream data have been collected, the HTTP connection is closed just before `someAsyncStuff` is invoked. Refactoring `pump(req, busboy...` to `req.pipe(busboy)` fixes the issue. It's also my understanding that using `pump` is a best practice for piping streams (for error handling and some clean-up), but in this case it introduces an issue. I would like to understand why this example is not working as I was expecting.
```typescript
import * as Busboy from 'busboy'
import * as express from 'express'
import * as pump from 'pump'
import concat = require('concat-stream')
const app = express()
app.post('/', (req, res) => {
const busboy = new Busboy({ headers: req.headers })
busboy.on('file', (_, file) => {
pump(
file,
concat(buffer =>
someAsyncStuff(buffer.toString())
.then(length => res.send({ length }))
.catch(err => res.status(500).send(err.message))
),
err => {
if (err) res.status(500).send(err.message)
}
)
})
pump(req, busboy, err => {
if (err) res.status(500).send(err.message)
})
})
function someAsyncStuff(s: string): Promise {
return new Promise(resolve => setTimeout(() => resolve(s.length), 1))
}
app.listen('3000')
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the TypeScript example in the issue and compare pump(req, busboy) with req.pipe(busboy). Trace the two pump calls, including the file stream and concat-stream callback, to determine why the HTTP connection closes before someAsyncStuff completes. Done means documenting when this usage of pump differs from piping directly and explaining the observed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100