Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJs ECONNRESET

I get an error when I'm executing GET request.

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

It happens when I try to make GET request to https://www.adidas.co.uk/api/search/taxonomy?query=men but it works when I use https://jsonplaceholder.typicode.com/api/todos/1.

Request:

var request = require('request');
[...]
app.use('/api', cacheMiddleware(), function (req, out) {


      var headers = {
        //'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
        'Content-Type': 'application/x-www-form-urlencoded'
        //'Content-Type': 'application/jsond'
      };

      var url = getDestinationUrl(req);
      if (req.method === 'POST') {
        console.log('POST body:')
        console.log(req.body);
        result = request.post({ uri: url, json: req.body, headers: headers, followRedirect: true , maxRedirects: 10}, function (error, response, body) { handleResponse(req, out, error, response, body) });
      } else {
        result = request({ uri: url, headers: headers, followRedirect: true,  maxRedirects: 10 }, function (error, response, body) { handleResponse(req, out, error, response, body) });
      }

    });

log:

    handle https://www.adidas.co.uk/api/search/taxonomy?query=men
REQUEST { uri: 'https://www.adidas.co.uk/api/search/taxonomy?query=men',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  followRedirect: true,
  maxRedirects: 10,
  callback: [Function] }
HTTP 10384: SERVER socketOnParserExecute 739
REQUEST make request https://www.adidas.co.uk/api/search/taxonomy?query=men
HTTP 10384: call onSocket 0 0
HTTP 10384: createConnection www.adidas.co.uk:443:::::::::::::::: { servername: 'www.adidas.co.uk',
  _defaultAgent:
   Agent {
     _events: [Object: null prototype] { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: { 'www.adidas.co.uk:443::::::::::::::::': [] },
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  _events:
   [Object: null prototype] {
     error: [Function: bound ],
     complete: [Function: bound ],
     pipe: [Function] },
  _eventsCount: 3,
  _maxListeners: undefined,
  uri:
   Url {
     protocol: 'https:',
     slashes: true,
     auth: null,
     host: 'www.adidas.co.uk',
     port: 443,
     hostname: 'www.adidas.co.uk',
     hash: null,
     search: '?query=men',
     query: 'query=men',
     pathname: '/api/search/taxonomy',
     path: '/api/search/taxonomy?query=men',
     href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
  headers:
   { 'Content-Type': 'application/x-www-form-urlencoded',
     host: 'www.adidas.co.uk' },
  followRedirect: true,
  maxRedirects: 10,
  callback: [Function],
  readable: true,
  writable: true,
  _qs:
   Querystring {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Circular],
        _auth: [Auth],
        _oauth: [OAuth],
        _multipart: [Multipart],
        _redirect: [Redirect],
        _tunnel: [Tunnel],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     lib:
      { formats: [Object], parse: [Function], stringify: [Function] },
     useQuerystring: undefined,
     parseOptions: {},
     stringifyOptions: {} },
  _auth:
   Auth {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Querystring],
        _auth: [Circular],
        _oauth: [OAuth],
        _multipart: [Multipart],
        _redirect: [Redirect],
        _tunnel: [Tunnel],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     hasAuth: false,
     sentAuth: false,
     bearerToken: null,
     user: null,
     pass: null },
  _oauth:
   OAuth {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Querystring],
        _auth: [Auth],
        _oauth: [Circular],
        _multipart: [Multipart],
        _redirect: [Redirect],
        _tunnel: [Tunnel],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     params: null },
  _multipart:
   Multipart {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Querystring],
        _auth: [Auth],
        _oauth: [OAuth],
        _multipart: [Circular],
        _redirect: [Redirect],
        _tunnel: [Tunnel],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     boundary: '54c4df7c-a16d-45e6-a57b-bb7f83e6b1fa',
     chunked: false,
     body: null },
  _redirect:
   Redirect {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Querystring],
        _auth: [Auth],
        _oauth: [OAuth],
        _multipart: [Multipart],
        _redirect: [Circular],
        _tunnel: [Tunnel],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     followRedirect: true,
     followRedirects: true,
     followAllRedirects: false,
     followOriginalHttpMethod: false,
     allowRedirect: [Function],
     maxRedirects: 10,
     redirects: [],
     redirectsFollowed: 0,
     removeRefererHeader: false },
  _tunnel:
   Tunnel {
     request:
      Request {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        uri: [Url],
        headers: [Object],
        followRedirect: true,
        maxRedirects: 10,
        callback: [Function],
        readable: true,
        writable: true,
        _qs: [Querystring],
        _auth: [Auth],
        _oauth: [OAuth],
        _multipart: [Multipart],
        _redirect: [Redirect],
        _tunnel: [Circular],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        method: 'GET',
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function],
        proxy: null,
        tunnel: true,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: 443,
        host: 'www.adidas.co.uk',
        path: '/api/search/taxonomy?query=men',
        httpModule: [Object],
        agentClass: [Function],
        agent: [Agent],
        _started: true,
        href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
     proxyHeaderWhiteList:
      [ 'accept',
        'accept-charset',
        'accept-encoding',
        'accept-language',
        'accept-ranges',
        'cache-control',
        'content-encoding',
        'content-language',
        'content-location',
        'content-md5',
        'content-range',
        'content-type',
        'connection',
        'date',
        'expect',
        'max-forwards',
        'pragma',
        'referer',
        'te',
        'user-agent',
        'via' ],
     proxyHeaderExclusiveList: [] },
  setHeader: [Function],
  hasHeader: [Function],
  getHeader: [Function],
  removeHeader: [Function],
  method: 'GET',
  localAddress: undefined,
  pool: {},
  dests: [],
  __isRequestRequest: true,
  _callback: [Function],
  proxy: null,
  tunnel: true,
  setHost: true,
  originalCookieHeader: undefined,
  _disableCookies: true,
  _jar: undefined,
  port: 443,
  host: 'www.adidas.co.uk',
  path: null,
  httpModule:
   { Agent: { [Function: Agent] super_: [Function] },
     globalAgent:
      Agent {
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: [Object] },
     Server: { [Function: Server] super_: [Function] },
     createServer: [Function: createServer],
     get: [Function: get],
     request: [Function: request] },
  agentClass:
   { [Function: Agent]
     super_:
      { [Function: Agent] super_: [Function], defaultMaxSockets: Infinity } },
  agent:
   Agent {
     _events: [Object: null prototype] { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: { 'www.adidas.co.uk:443::::::::::::::::': [] },
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  _started: true,
  href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men',
  _agentKey: 'www.adidas.co.uk:443::::::::::::::::' }
HTTP 10384: sockets www.adidas.co.uk:443:::::::::::::::: 1
HTTP 10384: outgoing message end.
HTTP 10384: SOCKET ERROR: read ECONNRESET Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)
handleResponse...
Response error
{ Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
HTTP 10384: outgoing message end.
HTTP 10384: CLIENT socket onClose
HTTP 10384: removeSocket www.adidas.co.uk:443:::::::::::::::: writable: false
HTTP 10384: HTTP socket close
HTTP 10384: server socket close

UPDATE: It works with axios:

app.use('/api', cacheMiddleware(), function (req, out) {
  var url = getDestinationUrl(req);
  if (req.method === 'POST') {
    axios.post(url, req.body)
      .then(response => {
        handleResponse(req, out, response, response.data)
      })
      .catch(error => {
        handleResponseError(req, out, error)
      });
  } else {
    axios.get(url)
      .then(response => {
        handleResponse(req, out, response, response.data)
      })
      .catch(error => {
        handleResponseError(req, out, error)
      });
  }
});
like image 237
Damian Avatar asked Dec 24 '18 10:12

Damian


People also ask

How do I fix Econnreset error?

I solved the problem by simply connecting to a different network. That is one of the possible problems. As discussed above, ECONNRESET means that the TCP conversation abruptly closed its end of the connection. Your internet connection might be blocking you from connecting to some servers.

What is err in Node JS?

An error in Node. js is any instance of the Error object. Common examples include built-in error classes, such as ReferenceError , RangeError , TypeError , URIError , EvalError , and SyntaxError .

What is error stack Nodejs?

The stack trace is used to trace the active stack frames at a particular instance during the execution of a program. The stack trace is useful while debugging code as it shows the exact point that has caused an error. Errors in Node.


1 Answers

Besides the above correct answers, this might help somebody.

I experienced the same error message. In my case the env variable for the server I had 'https://servername' instead of 'servername'. Removing the 'https://' piece fix the error.

like image 83
yaach Avatar answered Oct 21 '22 07:10

yaach