commit 0c85f296ad7037723638fb68ecaf81c1e0f8eb2b Author: Luke Childs Date: Thu Jun 9 20:19:50 2022 +0700 Initial commit diff --git a/api/async.js b/api/async.js new file mode 100644 index 0000000..5b10aa3 --- /dev/null +++ b/api/async.js @@ -0,0 +1,9 @@ +const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + +export default async function handler(request, response) { + console.log('before'); + response.send('hello, world!'); + await delay(100); + // This doesn't get logged + console.log('after'); +} \ No newline at end of file diff --git a/api/sync.js b/api/sync.js new file mode 100644 index 0000000..6c5f9c5 --- /dev/null +++ b/api/sync.js @@ -0,0 +1,6 @@ +export default function handler(request, response) { + console.log('before'); + response.send('hello, world!'); + // This gets logged + console.log('after'); +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..107332a --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +# Vercel Bug + +It seems that when a response is sent Vercel makes the assumption that everything is finished and prematurely kills an async handler instead of waiting for the Promise to resolve. This means any work deferred to the next tick after the response is sent will not be completed. + +I think this is a bug, it's inconsistent with how synchronous handlers work and I would intuitively expect that if a handler returns a Promise, that Vercel would wait for that Promise to resolve before killing the process. \ No newline at end of file