Skip to content

Commit

Permalink
WIP avoid 10s timeout - needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Aug 15, 2020
1 parent 9ad154d commit 5e21bcd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export function middleware(

debugWebhooks(`${eventName} event received (id: ${id})`);

// GitHub will abort the request if it does not receive a response within 10s
// See https://github.com/octokit/webhooks.js/issues/185
let didTimeout = false;
const timeout = setTimeout(() => {
didTimeout = true;
response.statusCode = 200;
response.end("still processing\n");
}, 9000);

return getPayload(request)
.then((payload: any) => {
return verifyAndReceive(state, {
Expand All @@ -59,10 +68,16 @@ export function middleware(
})

.then(() => {
if (didTimeout) return;
clearTimeout(timeout);

response.end("ok\n");
})

.catch((error: WebhookEventHandlerError) => {
if (didTimeout) return;
clearTimeout(timeout);

const statusCode = Array.from(error)[0].status;
response.statusCode = statusCode || 500;
response.end(error.toString());
Expand Down

0 comments on commit 5e21bcd

Please sign in to comment.