Skip to content

Commit

Permalink
Fix HTTP 502s from AWS ALB
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk authored and yavorg committed Jan 23, 2020
1 parent 3e2e063 commit dbcfd9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
24 changes: 19 additions & 5 deletions api/function-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import debug from 'debug';
process.env.DEBUG = process.env.DEBUG || 'fusebit';

import Debug from 'debug';
import http from 'http';
import app from './app';

debug('flexd-functions:server');
const debug = Debug('fusebit');
debug('Starting');

process.on('uncaughtException', (e: Error) => {
debug('UNCAUGHT ERROR:', e.stack || e);
setTimeout(() => process.exit(1), 100);
});

const normalizedPort = normalizePort(process.env.PORT || 3001);
app.set('port', normalizedPort);

const server = http.createServer(app);
server.listen(normalizedPort);
// Work-around for the Node 10.15.3 issue
// See https://shuheikagawa.com/blog/2019/04/25/keep-alive-timeout/
// See https://github.com/nodejs/node/issues/27363
// ALB timeout is 120s
server.keepAliveTimeout = 130 * 1000;
server.headersTimeout = 150 * 1000;

server.listen(normalizedPort);
server.on('error', onError);
server.on('listening', onListening);

Expand Down Expand Up @@ -39,11 +53,11 @@ function onError(error: any) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
debug(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
debug(bind + ' is already in use');
process.exit(1);
break;
default:
Expand Down
6 changes: 6 additions & 0 deletions docs/fusebit-http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ All public releases of the Fusebit HTTP API are documented here, including notab
<!-- 1. TOC
{:toc} -->

## Version 1.14.2

_Released 1/22/20_

- **Bug fix** Mitigation for a race condition in keep-alive timing between AWS ALB and Fusebit server that resulted in sporadic HTTP 502 responses.

## Version 1.14.1

_Released 1/13/20_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.14.1",
"version": "1.14.2",
"private": true,
"org": "5qtrs",
"scripts": {
Expand Down

0 comments on commit dbcfd9d

Please sign in to comment.