Repository navigation
AxiosError: socket hang up #6277
Replies: 1 comment
|
From the stack trace, this is running in a Next.js server component / RSC context, so Axios is using the Node Common causes to check:
A useful isolation step is to run the same request from the same server/container with You can also try disabling keep-alive to rule out stale sockets: import axios from 'axios';
import http from 'node:http';
import https from 'node:https';
const api = axios.create({
timeout: 30000,
httpAgent: new http.Agent({ keepAlive: false }),
httpsAgent: new https.Agent({ keepAlive: false })
});
const response = await api.get(url);
For production, treat ECONNRESET as a transient network failure and retry only safe/idempotent requests, such as GET:
async function getWithRetry(url, attempts = 3) {
let lastError;
for (let i = 0; i < attempts; i++) {
try {
return await axios.get(url, { timeout: 30000 });
} catch (err) {
lastError = err;
if (err.code !== 'ECONNRESET') {
throw err;
}
}
}
throw lastError;
}If you can share the Axios request config, target URL shape, Axios version, Node version, and whether this happens locally or only after deployment, it would be easier to identify the exact cause. |
Uh oh!
There was an error while loading. Please reload this page.
AxiosError: socket hang up
at AxiosError.from (webpack-internal:///(rsc)/./node_modules/axios/lib/core/AxiosError.js:85:16)
at RedirectableRequest.handleRequestError (webpack-internal:///(rsc)/./node_modules/axios/lib/adapters/http.js:531:81)
at RedirectableRequest.emit (node:events:527:35)
at eventHandlers. (webpack-internal:///(rsc)/./node_modules/follow-redirects/index.js:42:28)
at ClientRequest.emit (node:events:515:28)
at TLSSocket.socketOnEnd (node:_http_client:519:9)
at TLSSocket.emit (node:events:527:35)
at endReadableNT (node:internal/streams/readable:1589:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (webpack-internal:///(rsc)/./node_modules/axios/lib/core/Axios.js:50:49)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getData (webpack-internal:///(rsc)/./app/[city]/[...category]/page.js:85:26)
at async Category (webpack-internal:///(rsc)/./app/[city]/[...category]/page.js:30:18) {
code: 'ECONNRESET',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ 'xhr', 'http' ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 30000,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: [class Blob] },
validateStatus: [Function: validateStatus],
All reactions