req.multipart() does not await for all multipartfield handler async functions? #100
-
Edit: Actual description of the issue is in this reply: #100 (comment) Original: I did not notice this before since I initially was just doing things such as piping file's ReadStream into a WriteStream, which basically ends almost immediately as the ReadStream itself finishes But after I start playing with some Transform stream that needs slightly longer time than usual, I finally notice that req.multipart appears to resolve almost immediately, even if there's a MultipartField handler async function still working in the background Suppose the following code snippets routes.post('/api/upload', async (req, res) => {
console.log('1')
await req.multipart(busboyConfig, async field => {
await new Promise(resolve => setTimeout(() => resolve(), 5000))
console.log('2')
}
console.log('3')
res.status(200).end()
}
}) Console output would be:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
It appears that it will only await if the handler function explicitly returns a Promise, because the code internally checks if it's an |
Beta Was this translation helpful? Give feedback.
-
Ah, my bad, it wasn't that it did not await Instead, from what I can tell, req.multipart resolves early when So assuming I have multi-step pipes: field.file.stream
.pipe(destStream1)
.pipe(destStream2) req.multipart() somehow resolves after destStream1 has finished consuming the stream, even though destStream2 is still doing it things |
Beta Was this translation helpful? Give feedback.
-
While there is no built-in request timeout anywhere in HyperExpress, there is a hard-coded security inactivity timeout of ~10 seconds built into uWebsockets.js which is likely what you are experiencing here. Essentially if the socket does not send or receive any content for 10 seconds then uWebsockets.js will automatically timeout the request. See https://github.com/uNetworking/uWebSockets/blob/5eb463580913486493d97a410d354a2085681147/src/HttpContext.h#L43-L44
This would be really weird / shouldn't even be possible but add the following snippet to your route: // Add a random UUID to each request to "track" it
if (!request.id) request.id = crypto.randomUUID();
console.log('Received Request ' + request.id); Then try to see If the same UUID is logged to console twice which would signify that HyperExpress called the route handler with the same |
Beta Was this translation helpful? Give feedback.
Ah, my bad, it wasn't that it did not await
It did await properly with that example code in the original post
Instead, from what I can tell, req.multipart resolves early when
field.file.stream
has been consumed by the first Transform/Writable stream I piped it into, even though the handler function is still supposed to await for the remaining destination streams if anySo assuming I have multi-step pipes:
req.multipart() somehow resolves after destStream1 has finished consuming the stream, even though destStream2 is still doing it things