Request: Request getting ESOCKETTIMEDOUT consistently when all other clients work (http://www.bestbuy.com)

Created on 10 Aug 2017  ·  6Comments  ·  Source: request/request

Hello,

very easy to reproduce and always happens!

const request = require('request');
const axios = require('axios');
const url = 'http://www.bestbuy.com/';
request({
    url: url,
    timeout: 5000
}, (error, response, body) => {
    if (!error)
        console.log(`request got ${response.statusCode}`);
    else
        console.error(`request got an error`, error);
});

axios.get(url).then((ret) => {
    console.log(`Axios got ${ret.status}`);
});

outputs:

Axios got 200
request got an error { Error: ESOCKETTIMEDOUT
    at ClientRequest.<anonymous> (/Users/amir/dev/test/testVideosFb/node_modules/request/request.js:819:19)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:86:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.emitTimeout (_http_client.js:679:10)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:86:13)
    at Socket.emit (events.js:188:7)
    at Socket._onTimeout (net.js:345:8)
    at ontimeout (timers.js:380:14) code: 'ESOCKETTIMEDOUT', connect: false }

My environment is node 7.7.2/8.3.0 and [email protected]

stale

Most helpful comment

I think bestbuy.com may be blocking the request due to the default headers being sent from request. If the request is made with the same headers that the axios request is sending, it does not time out:

const request = require('request');
const axios = require('axios');
const url = 'http://www.bestbuy.com/';
request({
  url: url,
  timeout: 5000,
  headers: {
    "Accept": "application/json, text/plain, */*",
    "User-Agent": "axios/0.18.0"
  }
}, (error, response, body) => {
  if (!error)
    console.log(`request got ${response.statusCode}`);
  else
    console.error(`request got an error`, error);
});

axios.get(url).then((ret) => {
  console.log(`Axios got ${ret.status}`);
});

All 6 comments

It would be nice to have some feedback on this ESOCKETTIMEOUT issue since I got it too and I don't found any way to solve this issue without changing this module.

Is the ESOCKETTIMEOUT related to an issue with the socket pooling ? I thought soo so I did disable socket pooling in node with

`var http = require('http');
http.globalAgent.maxSockets = Infinity;

var https = require('https');
https.globalAgent.maxSockets = Infinity;`

but it didn't change anything about not getting the ESOCKETTIMEOUT someone as a solution for this error ?

same issue for me

I found if there are too many async requests, then ESOCKETTIMEDOUT exception happens in linux. The workaround I've found is doing this:

setting this options to request():

agent: false, pool: {maxSockets: 100}

Notice that after that, the timeout can be lying so you might need to increase it.

Same issue here +1
agent: false, pool: {maxSockets: 100} didn't help

I think bestbuy.com may be blocking the request due to the default headers being sent from request. If the request is made with the same headers that the axios request is sending, it does not time out:

const request = require('request');
const axios = require('axios');
const url = 'http://www.bestbuy.com/';
request({
  url: url,
  timeout: 5000,
  headers: {
    "Accept": "application/json, text/plain, */*",
    "User-Agent": "axios/0.18.0"
  }
}, (error, response, body) => {
  if (!error)
    console.log(`request got ${response.statusCode}`);
  else
    console.error(`request got an error`, error);
});

axios.get(url).then((ret) => {
  console.log(`Axios got ${ret.status}`);
});

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings