-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Unparsed stream payload breaks under node 14 #4149
Comments
Interesting. This might be an FYI, hapi does literally nothing with |
It does seem to work without const http = require('http')
const Hapi = require('@hapi/hapi')
const server = Hapi.server({
port: 12345
})
server.route({
method: 'POST',
path: '/derp',
options: {
payload: {
parse: true,
output: 'stream'
}
},
async handler (request, h) {
console.info('start reading')
for await (const chunk of request.payload) {
console.info('got chunk', chunk.toString())
}
console.info('done reading')
return 'ok'
}
})
async function main () {
await server.start()
const req = http.request({
hostname: '127.0.0.1',
port: 12345,
path: '/derp',
method: 'POST'
}, (res) => {
console.info('got response', res.statusCode)
res.resume()
res.on('end', () => {
server.stop()
.catch(printErrorAndExit)
})
})
req.write(Buffer.from('hello world'))
req.end()
}
main()
.catch(printErrorAndExit)
function printErrorAndExit (err) {
console.error(err)
process.exit(1)
} $ node --version
v14.8.0
$ node test.js
start reading
got chunk hello world
done reading
got response 200
$ echo $?
0 |
Thanks. I'm looking into fixing shot now. |
It also works if I use events instead of const Hapi = require('@hapi/hapi')
const server = Hapi.server()
server.route({
method: 'POST',
path: '/derp',
options: {
payload: {
parse: false,
output: 'stream'
}
},
async handler (request, h) {
console.info('start reading')
let done
const promise = new Promise((resolve) => {
done = resolve
})
request.payload.on('data', (chunk) => {
console.info('got chunk', chunk.toString())
})
request.payload.on('end', () => {
console.info('done reading')
done('ok')
})
return promise
}
})
server.inject({
method: 'POST',
url: '/derp',
payload: Buffer.from('hello world')
})
.then(res => {
console.info('got response', res.statusCode)
})
.catch(err => {
console.error(err)
process.exit(1)
}) $ node --version
v14.8.0
$ node test.js
start reading
got chunk hello world
done reading
got response 200 |
Commenting out the implementation of The docs say:
I guess this is why! |
Yeah, I have seen this issue with the EOS detection in the async iterator before. Fix in hapijs/shot#129, awaiting someone to review & publish. |
shot@5.0.2 has been published. |
Great stuff, thanks for the speedy resolution! |
shot@5.0.3 has been released, which reverted the previous change. We'll need to look at a different approach. |
The node docs say: > Implementors should not override this method, but instead implement readable._destroy() Fixes hapijs/hapi#4149
I've opened hapijs/shot#132 - it's a bit simpler than the original fix, notably it doesn't try to change the |
The node docs say: > Implementors should not override this method, but instead implement readable._destroy() Fixes hapijs/hapi#4149
* fix: do not override destroy method The node docs say: > Implementors should not override this method, but instead implement readable._destroy() Fixes hapijs/hapi#4149 * do not autodestroy request stream * restore destroy method * Revert changes in favor of #133, keeping new test Co-authored-by: Alex Potsides <alex@achingbrain.net> Co-authored-by: devin ivy <devin@bigroomstudios.com>
* fix: do not override destroy method The node docs say: > Implementors should not override this method, but instead implement readable._destroy() Fixes hapijs/hapi#4149 * do not autodestroy request stream * restore destroy method * Revert changes in favor of #133, keeping new test Co-authored-by: Alex Potsides <alex@achingbrain.net> Co-authored-by: devin ivy <devin@bigroomstudios.com>
Support plan
Context
What are you trying to achieve or the steps to reproduce?
Setting route options as:
Works with node 12 but breaks with node 14.
A full example (using @hapi/hapi@20.0.0):
What was the result you got?
node@12:
node@14:
Setting
output
to'data'
makes it work as expected in both node versions, but buffers the whole payload into memory so can't be used.Keeping
output
as'stream'
, settingparse
totrue
and passing an appropriatecontent-type
along with the message breaks in the same way as settingparse
tofalse
.What result did you expect?
The same behaviour under node 12 and node 14 when
output
is'stream'
andparse
isfalse
.The text was updated successfully, but these errors were encountered: