Skip to content

Commit

Permalink
Set the keep alive timeout to 31 seconds (#1111)
Browse files Browse the repository at this point in the history
* Set the keep alive timeout to 30.5 seconds

* extend window to 31 seconds

* Update .changeset/fair-shrimps-count.md

Co-authored-by: Ryan Ling <ryan@outlook.com.au>

* Update template/koa-rest-api/src/listen.ts

Co-authored-by: Ryan Ling <ryan@outlook.com.au>

* Update template/express-rest-api/src/listen.ts

Co-authored-by: Ryan Ling <ryan@outlook.com.au>

---------

Co-authored-by: Ryan Ling <ryan@outlook.com.au>
  • Loading branch information
samchungy and 72636c authored Mar 3, 2023
1 parent f159af0 commit cab3636
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .changeset/fair-shrimps-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'skuba': patch
---

template/\*-rest-api: Set `keepAliveTimeout` to 31 seconds to prevent HTTP 502s

The default Node.js server keep-alive timeout is set to 5 seconds. However, the Gantry default ALB idle timeout is 30 seconds. This would lead to the occasional issues where the sidecar would throw `proxyStatus=502` errors. AWS recommends setting an application timeout larger than the ALB idle timeout.

A more detailed explanation can be found in the below links:

1. <https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#connection-idle-timeout>
2. <https://nodejs.org/docs/latest-v18.x/api/http.html#serverkeepalivetimeout>
7 changes: 7 additions & 0 deletions template/express-rest-api/src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ const listener = app.listen(config.port, () => {
rootLogger.debug(`listening on port ${address.port}`);
}
});

// Gantry ALB default idle timeout is 30 seconds
// https://nodejs.org/docs/latest-v18.x/api/http.html#serverkeepalivetimeout
// Node default is 5 seconds
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#connection-idle-timeout
// AWS recommends setting an application timeout larger than the load balancer
listener.keepAliveTimeout = 31000;
7 changes: 7 additions & 0 deletions template/koa-rest-api/src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ const listener = app.listen(config.port, () => {
logger.debug(`listening on port ${address.port}`);
}
});

// Gantry ALB default idle timeout is 30 seconds
// https://nodejs.org/docs/latest-v18.x/api/http.html#serverkeepalivetimeout
// Node default is 5 seconds
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#connection-idle-timeout
// AWS recommends setting an application timeout larger than the load balancer
listener.keepAliveTimeout = 31000;

0 comments on commit cab3636

Please sign in to comment.