Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

fix: do not back-off on intake req errors in Lambda env #180

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# elastic-apm-http-client changelog

## Unreleased

- Fix an issue when running in a Lambda function, where a missing or erroring
APM Lambda extension could result in apmclient back-off such that (a) the
end-of-lambda-invocation signaling (`?flushed=true`) would not happen and
(b) premature "beforeExit" event could result in the Lambda Runtime
responding `null` before the Lambda function could respond
(https://github.com/elastic/apm-agent-nodejs/issues/1831).

## v11.0.0

- Add support for coordinating data flushing in an AWS Lambda environment. The
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,18 @@ Client.prototype._destroy = function (err, cb) {
// Return the appropriate backoff delay (in milliseconds) before a next possible
// request to APM server.
// Spec: https://github.com/elastic/apm/blob/main/specs/agents/transport.md#transport-errors
//
// In a Lambda environment, a backoff delay can be harmful: The backoff
// setTimeout is unref'd, to not hold the process open. A subsequent Lambda
// function invocation during that timer will result in no active handles and
// a process "beforeExit" event. That event is interpreted by the Lambda Runtime
// as "the Lambda function callback was never called", and it terminates the
// function and responds with `null`. The solution is to never backoff in a
// Lambda environment -- we expect and assume the Lambda extension is working,
// and pass responsibility for backoff to the extension.
Client.prototype._getBackoffDelay = function (isErr) {
let reconnectCount = this._backoffReconnectCount
if (isErr) {
if (isErr && !isLambdaExecutionEnvironment) {
this._backoffReconnectCount++
} else {
this._backoffReconnectCount = 0
Expand Down