'read:ECONNRESET with Axios
I've encountered read:ECONNRESET error while I was trying to some data through axios post.
A configuration for Axios is
const http = require('http');
const https = require('https');
const axios = require('axios').create({
//keepAlive pools and reuses TCP connections, so it's faster
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
});
function to send post request is
axios.post(`${HOST}/sendEmail/`, qs.stringify(params))
.then(() => {
if (conversation.managerUnreadCount) {
console.log('[todo] conversation.managerUnreadCount ', conversation.managerUnreadCount);
}
})
.catch((err) => {
console.error('err in axios', err, url);
});
Error is below..
{ Error: read ECONNRESET
at exports._errnoException (util.js:1020:11)
at TLSWrap.onread (net.js:580:26)
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read',
config:
{ adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'axios/0.16.2',
'Content-Length': 737 },
httpAgent:
Agent {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options: [Object],
requests: {},
sockets: {},
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256 },
httpsAgent:
Agent {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: [Object],
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object] },
method: 'post',
url: 'https://us-central1-customurl.cloudfunctions.net/sendEmail/',
data: 'fromEmail=testerA11%40mailinator.com&fromEmailName=tester%20A11&replyTo=testerA11%40msg.dev.hostthere.email&replyToName=tester%20A11&toEmail=hostthere.auth.test%40gmail.com&subject=test%20...*(custom data string here)*' },
request:
Writable {
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: false,
ended: false,
finished: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
domain: null,
_events:
{ response: [Function: handleResponse],
error: [Function: handleRequestError] },
_eventsCount: 2,
_maxListeners: undefined,
_options:
{ protocol: 'https:',
maxRedirects: 21,
maxBodyLength: 10485760,
hostname: 'us-central1-customurl.cloudfunctions.net',
port: null,
path: '/sendEmail/',
method: 'post',
headers: [Object],
agent: [Object],
auth: undefined,
nativeProtocols: [Object],
pathname: '/sendEmail/' },
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 737,
_requestBodyBuffers: [ [Object] ],
_onNativeResponse: [Function],
_currentRequest:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: false,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: false,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'POST /sendEmail/ HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: axios/0.16.2\r\nContent-Length: 737\r\nHost: us-central1-customurl.cloudfunctions.net\r\nConnection: keep-alive\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
... }
And in my system many different post requests are made at same time. (not same url with above)
I thought if I added keep-alive options where axios created, but it did not help.
Any other ideas to resolve this error?
Thank you for reading.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|