Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

637
Visualizações
AWS ElasticBeanstalk NodeJS - 502 error: recv() failed (104: Connection reset by peer) while reading response header from upstream

We are planning to migrate our NodeJS platform from plain EC2 to ElasticBeanstalk. During these process, after some struggles, we have deployed our app and able to access and perform actions. However, for some requests, we received 502 error.

After checking the logs we found below;


/var/log/nginx/error.log

2020/03/16 06:12:09 [error] 3009#0: *119488 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxx.xx.xx.xxx, server: , request: "POST /www_auth/register HTTP/1.1", upstream: "http://127.0.0.1:8081/register", host: "****.us-east-2.elasticbeanstalk.com"

It occurs in randomly and I don't have any clue. I feel some configuration level changes I missed/need to add with nginx.

If you have any steps/suggestions to solve this, appreciate it!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

AWS Elastic Load Balancer pre-connects to backend servers, and it can cause a race condition where ELB thinks a connection is open, but the Node.js backend has already closed it, due to the server.keepAliveTimeout of 5 seconds of idle inactivity, the default value in Node.js 8.x and newer.

Disable server.keepAliveTimeout and server.headersTimeout to work around this issue, or set these timeouts to a ms value larger than the AWS ELB's Idle Timeout value.

const app = express();

// Set up the app...
const server = app.listen(8080);

// Disable both timeouts
server.keepAliveTimeout = 0;
server.headersTimeout = 0;

Credit for this solution goes to Shuhei Kagawa:

https://shuheikagawa.com/blog/2019/04/25/keep-alive-timeout/

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda