Browse Source

Initial commit

master
Luke Childs 2 years ago
commit
0c85f296ad
  1. 9
      api/async.js
  2. 6
      api/sync.js
  3. 5
      readme.md

9
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');
}

6
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');
}

5
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.
Loading…
Cancel
Save