Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

unhandled proxy ECONNREFUSED #6

Open
Freaders opened this issue Mar 13, 2017 · 8 comments
Open

unhandled proxy ECONNREFUSED #6

Freaders opened this issue Mar 13, 2017 · 8 comments

Comments

@Freaders
Copy link

Freaders commented Mar 13, 2017

Error: connect ECONNREFUSED xxx.xxx.xxx.xxx:xxxx
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)

Is it possible to somehow handle this error?? If the proxy server doesnt respond the client crashes.

my code:

this.steamclient = new steam.CMClient();
this.steamclient.setHttpProxy(proxyUrl);

this.client = new SteamUser(this.steamclient);

also

this.proxifiedRequest = request.defaults({'proxy': proxyUrl});
this.community = new SteamCommunity({request: this.proxifiedRequest});
this.client.on('webSession', function(sessionID, cookies){
		self.community.setCookies(cookies);
		self.manager.setCookies(cookies, function(err) {});
		self.community.startConfirmationChecker(15000, self.identitySecret);
	});
@DoctorMcKay
Copy link
Owner

Are you handling the error event on SteamUser?

@Freaders
Copy link
Author

this.client.on('error', function (err) {
		console.log("Steam Client error: ");
		console.log(err);
	});

doesnt help

@Aareksio
Copy link
Contributor

I'm pretty sure socket hang up error is connected to this, both are caused by malfunctioning proxy. In my case the flow is:

  • socket hang up throws up the script
  • Process manager restarts the script
  • ECONNREFUSED is thrown after the SteamUser.logOn is called

The problem is obviously caused by the proxy which drops / refuses connection. Temporary solution is to fix the proxy service, although it would be nice if we could handle it properly.

Error: socket hang up
    at createHangUpError (_http_client.js:254:15)
    at Socket.socketOnEnd (_http_client.js:346:23)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:122:9)

Handlers set as following:

_client.on('error', handleClientError);
_user.on('error', handleUserError);

I just noticed the handler (currently can't say which one, as it was logging only error.toString()) catched Error: connect ECONNREFUSED xxx.xxx.xxx.xxx:xxxx just before the app threw up with the same error (exactly the one encountered by @Freaders).

In cm_client.js#L105 TCPConnection is used before error handler is set, may be the reason of ECONNREFUSED, the comment says error should be passed as the callback first argument, although it's the code from before proxy update.

@Freaders
Copy link
Author

i have proxies from third party provider so i cannot really "fix" them.. so i can use the steamclient.on('error', handleClientError); to catch the error and then reconnect the acc again to the steam?

@Aareksio
Copy link
Contributor

You can get better proxies, that doesn't refuse the connection.
The error is being thrown despite handling error event on the client. I'm hoping that the reason for this is exposed in my previous comment, I'll check this out for sure after I'm done reading _http_client.js finding a solution for socket hang up :)

@Freaders
Copy link
Author

could you recommend any proxy provider? thanks

@Aareksio
Copy link
Contributor

Aareksio commented Mar 14, 2017

Moving error handler before the callback worked.

Tested on ETIMEDOUT, which was throwing before exactly like ECONNREFUSED and is easier to reproduce.

Moving the error outside the callback should be safe, as the object gets deleted in CMClient._disconnected upon connection failure.

Test code:

const SteamClient = require('steam-client');
const SteamUser = require('steam-user');

const client = new SteamClient.CMClient();
client.setHttpProxy('http://timeouting-proxy');

const user = new SteamUser(client);

client.on('error', (...data) => console.log('client-error', ...data));
client.on('debug', (...data) => console.log('client-debug', ...data));
user.on('error', (...data) => console.log('user-error', ...data));

user.logOn({ accountName: 'XXX', password: 'XXX' });

@Freaders
Copy link
Author

That works! Any advice how to properly handle this? Thank you very much.

/bot/node_modules/steam-user/components/web.js:9
                throw new Error("Cannot log onto steamcommunity.com without first being connected to Steam network");
                ^

Error: Cannot log onto steamcommunity.com without first being connected to Steam network
    at SteamUser.webLogOn (/bot/node_modules/steam-user/components/web.js:9:9)
    at Timeout._onTimeout (/bot/bot.js:462:30)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
error: Forever detected script exited with code: 1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants