Skip to content

Lambda function hangs after upgrading Node.js Lambda Layer (Undici / Custom Agent Conflict) #390

@AndreWeberClarks

Description

@AndreWeberClarks

Description

Upgrading the AWS Lambda layer to the new unified architecture causes the Lambda function to hang indefinitely and hit its hard timeout limit. This regression occurs specifically when utilizing fetch with a custom undici Agent dispatcher configured to bypass certificate verification or handle self-signed endpoints.

Expected Behavior

The fetch request should execute, complete, and allow the Lambda function handler to resolve cleanly, as it did in the previous runtime-specific layer version.

Actual Behavior

The execution thread completely freezes at the moment of the fetch request call. The Lambda function sits in an unresolved state until the AWS Lambda execution timeout triggers.

Steps to Reproduce

Configure a Node.js 22 Lambda function with the following minimal setup:

import { fetch, Agent } from 'undici';

const customAgent = new Agent({
  connect: { rejectUnauthorized: false }
});

export const handler = async (event) => {
  // Execution freezes exactly right here
  const response = await fetch('https://my-self-signed-site.local', {
    dispatcher: customAgent
  });
  
  return await response.json();
};

Troubleshooting and Isolation

  1. Feature Flag Isolation: Setting the environment variable NEW_RELIC_INSTRUMENTATION_UNDICI_ENABLED: false completely resolves the issue. The function instantly runs and closes without timing out.
  2. Dispatcher Isolation: Leaving instrumentation enabled but commenting out the dispatcher: customAgent argument from the fetch options object also stops the timeout (though it obviously fails TLS verification for our target server). The loop lock is strictly linked to how the agent patches the custom Agent object.
  3. Symptom: It behaves as an internal unresolved promise chain or an infinite event loop block created when the monkey-patch wrapper attempts to parse explicit dispatcher runtime configuration properties in Node 22.

Relevant Logs / Console output

I attempted to gather diagnostic logs by setting NEW_RELIC_LOG_ENABLED: true, NEW_RELIC_LOG: stdout, and NEW_RELIC_LOG_LEVEL: trace.

Despite enabling maximum verbosity, the agent does not output any explicit error traces, crashes, or unhandled exceptions before freezing. The execution loop simply stalls out silently, and the only log received in AWS CloudWatch is the standard hard timeout warning emitted by the AWS Lambda runtime itself:

REPORT RequestId: ... Duration: 15003.45 ms Billed Duration: 15000 ms Memory Size: 512 MB Max Memory Used: ... 
2026-05-20T...Z ... Task timed out after 15.00 seconds

Your Environment

  • AWS Lambda Runtime: Node.js 22.x
  • Undici Package Version: 6.24.0
  • Working Layer ARN: arn:aws:lambda:eu-west-1:451483290750:layer:NewRelicNodeJS22XARM64:22
  • Broken Layer ARN: arn:aws:lambda:eu-west-1:451483290750:layer:NewRelicNodeJSARM64:10
  • Agent Framework Delta: Transitioning from the legacy runtime-pinned

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions