elastic / elastic/apm-agent-nodejs
ECONNRESET + TimeoutError
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
While the process is in idle state, two type of exceptions are thrown:
- APM Server transport error (ECONNRESET): socket hang up
- Sending error to Elastic APM { id: "..." }
What I have tried:
- use secret token instead of api-key
- the APM server is behind a load balancer but the there is no traffic blocked
- already tried re-creating multiple times users, roles and api-key
- changing the site where the client is hosted (the problem persists in both production and development environment)
**To Reproduce**
Steps to reproduce the behavior:
1. Use this config
`{
// Override service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: config.logs.elastic_apm.service_name,
// Use if APM Server uses ApiKey for authentication
apiKey: config.logs.elastic_apm.api_key,
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: config.logs.elastic_apm.server_url,
// The recorded body will be truncated if larger than 2 KiB
captureBody: config.logs.elastic_apm.capture_body,
// Prevent "Error: Unexpected APM Server response when polling config"
centralConfig: true,
ignoreUrls: ["/", "/alive", "/ready"],
active: config.logs.elastic_apm.enabled,
captureExceptions: false,
logLevel: "debug",
payloadLogFile: "./payload.ndjson"
}`
2. Then don't make calls and just wait
4. See error

**Expected behavior**
To not receive these type of errors
**Environment (please complete the following information)**
- OS: Mac OS 11.2.1 / Docker inside K8S 1.19.6
- Node.js version: 12 / 14.16 / 15.10
- APM Server version: 7.11.0
- Agent version: 3.10 / 3.11 / 3.12 / 3.12.1
**How are you starting the agent? (please tick one of the boxes)**
- [x] Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
- [ ] Requiring `elastic-apm-node/start` from within the source code
- [ ] Starting node with `-r elastic-apm-node/start`
**Additional context**
`[{"error":{"exception":{"message":"Request timed out","type":"TimeoutError","module":"@elastic/elasticsearch","stacktrace":[{"filename":"node_modules/@elastic/elasticsearch/lib/Connection.js","lineno":109,"function":"onTimeout","library_frame":true,"abs_path":"/Users/danielesarnari/Documents/Repositories/process-api-shub/node_modules/@elastic/elasticsearch/lib/Connection.js","pre_context":[" request.once('error', () => {}) // we need to catch the request aborted error"," request.abort()"],"context_line":" callback(new TimeoutError('Request timed out', params), null)","post_context":[" }",""]},{"filename":"node:events","lineno":378,"function":"emit","library_frame":true,"abs_path":"node:events"},{"filename":"node:_http_client","lineno":780,"function":"emitRequestTimeout","library_frame":true,"abs_path":"node:_http_client"},{"filename":"node:events","lineno":484,"function":"onceWrapper","library_frame":true,"abs_path":"node:events"},{"filename":"node:events","lineno":390,"function":"emit","library_frame":true,"abs_path":"node:events"},{"filename":"node:net","lineno":480,"function":"Socket._onTimeout","library_frame":true,"abs_path":"node:net"},{"filename":"node:internal/timers","lineno":557,"function":"listOnTimeout","library_frame":true,"abs_path":"node:internal/timers"},{"filename":"node:internal/timers","lineno":500,"function":"processTimers","library_frame":true,"abs_path":"node:internal/timers"}]},"culprit":"onTimeout (node_modules/@elastic/elasticsearch/lib/Connection.js)","id":"eebbb71863b3db37218c79d17c953fbf","timestamp":1614589876282000,"context":{"user":{},"tags":{},"custom":{}}}}]`

Additional tags for co-workers: @sp0kky
Contributor guide
Assessment
This issue has not been assessed yet.