Unverified Commit 40dd14ff authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Handle Promise Rejections for Streams (#56976)

This handles the promise rejection for chained streams better and the other case in the server setup when `prepre()` is fired off early.
parent 27b89e4a
...@@ -1024,9 +1024,14 @@ export default class NextNodeServer extends BaseServer { ...@@ -1024,9 +1024,14 @@ export default class NextNodeServer extends BaseServer {
} }
private makeRequestHandler(): NodeRequestHandler { private makeRequestHandler(): NodeRequestHandler {
// This is just optimization to fire prepare as soon as possible // This is just optimization to fire prepare as soon as possible. It will be
// It will be properly awaited later // properly awaited later. We add the catch here to ensure that it does not
void this.prepare() // cause a unhandled promise rejection. The promise rejection wil be
// handled later on via the `await` when the request handler is called.
this.prepare().catch((err) => {
console.error('Failed to prepare server', err)
})
const handler = super.getRequestHandler() const handler = super.getRequestHandler()
return (req, res, parsedUrl) => { return (req, res, parsedUrl) => {
const normalizedReq = this.normalizeReq(req) const normalizedReq = this.normalizeReq(req)
......
...@@ -64,6 +64,10 @@ export function chainStreams<T>( ...@@ -64,6 +64,10 @@ export function chainStreams<T>(
) )
} }
// Catch any errors from the streams and ignore them, they will be handled
// by whatever is consuming the readable stream.
promise.catch(() => {})
return readable return readable
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment