DEV Community

Tim Nguyen
Tim Nguyen

Posted on

AWS Lambda - Socket hang up Nodejs

Context: Lambda error said 'socket hang up' within nodejs code when performing http/https request to 3rd party backend

Let's describe my tries on solving the problem

  1. Increase the timeout of lambda -> Not help
  2. Increase the timeout of httpClient -> Not help
  3. Figure out that lambda having some problem with connection -> Put HttpAgent to keepalive the connection -> Work perfectly

Code demo:

new JwksClient({
      jwksUri: 'xxx' + '/oidc/2/certs',
      timeout: 10000,
      requestAgent: new Agent({
        keepAlive: true
      })
    })
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay