I’ve started seeing frequent “Client network socket disconnected before secure TLS connection was established” errors. These errors occur in Netlify functions used by a NextJS app.
Here’s the full stacktrace:
May 23, 10:29:50 PM: 9c64f5df ERROR FetchError: request to xxxxxxxxx failed, reason: Client network socket disconnected before secure TLS connection was established
at ClientRequest.<anonymous> (/var/task/node_modules/next/dist/compiled/node-fetch/index.js:1:64142)
at ClientRequest.emit (events.js:400:28)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
- The error occurs only on a single API endpoint (which is responsible for logging)
- The error is inconsistent on Netlify. Sometimes it happens, sometimes not.
- The error never occurs when developing locally
- The route the error originates from is itself sometimes fetched by separate API route
There seems to be a quite a few flavors of this error: Search results for 'Client network socket disconnected before secure TLS connection was established order:latest' - Netlify Support Forums. I’ve tried a few incantations to fix it (like ensuring I always await
every fetch, even when I don’t need/want to, and moving functionality both in and out of the function body of the API route), but nothing has worked. What’s particularly difficult about it is that the error is somewhat nondescript, and also inconsistent. Any help is appreciated. Thanks!