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)