`readRawBody` causes requests to hang when combined with websockets
Environment
- Operating System: Linux
- Node Version: v18.20.3
- Nuxt Version: 3.11.2
- CLI Version: 3.12.0
- Nitro Version: -
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, nitro
- Runtime Modules: -
- Build Modules: -
Reproduction
https://github.com/noook/nuxt-security-socket-io-repro (initially reported in nuxt-security, forwarding this here as the issue is located in a utility in h3, full credits to @noook for the reproduction)
A more isolated example with a manual implementation of the problem, modified from noook's original reproduction: https://stackblitz.com/edit/github-tjebrz?file=server%2Fmiddleware%2Ftest.ts
Describe the bug
When used with websockets (at least specifically from socket.io), POST requests hang as seen by the lack of console log of 'requested ID' in the nitro plugin. In the more isolated reproduction, the readRawBody is modified from h3 to include the source of the problem, which is the main body parsing promise.
I managed to trace the issue down to the line at fault, which is the data event listener in the promise. When keeping it commented, you can see the requests go through as expected in the devtools, and when uncommenting it, some of the requests hang.
Additional context
The issue doesn't seem to be about resolving inside the promise, as it works fine when using the hardcoded resolve. It in stead appears to be something internal specifically with listening for the data event.
Logs
There are no error logs