DoctorMcKay / node-steam-user

Allows interaction with the Steam network via the Steam client protocol
https://dev.doctormckay.com/forum/7-node-steam-user/
MIT License
892 stars 157 forks source link

Cannot catch "Already logged on, cannot log on again" error #481

Closed thecatontheflat closed 7 months ago

thecatontheflat commented 7 months ago

Describe the bug

The Already logged on, cannot log on again error is thrown when attempting to logOn() after proxy timeout. The issue started happening regularly during the Steam outages after we upgraded the node-steam-user package

Relevant bits from the code.

Initiating the user:

    this.steamUser = new SteamUser({
        httpProxy: proxyUrl,
        webCompatibilityMode: true,
        machineIdType: EMachineIDType?.AlwaysRandom || 2,
        autoRelogin: true,
    });

        this.steamUser.on('disconnected', (eresult, msg) => {
            console.log('Received disconnected event', eresult, msg);
        });

        this.steamUser.on('error', (error) => {

                // Steam ID is set, meaning it was a Steam induced disconnect event, so we exit
                if (this.steamUser?.steamID) return;

           console.error('Steam client disconnected, retrying connection', error.message);
        setTimeout(() => {
            this.steamUser.logOn(this.credential);
        }, 60 * 1000); // backing off for 1 minute
        });

At some point (usually happens during Steam downtime) the user gets disconnected (expected):

Received disconnected event 3 NoConnection

Autorelogin attempts to reconnect, which is expected too. This results in the following log message:

Steam client disconnected, retrying connection Proxy connection timed out

Then shortly after the following error is thrown:

Unhandled Promise Rejection Promise {
  <rejected> Error: Already attempting to log on, cannot log on again
      at SteamUser.logOn (/var/www/app/node_modules/steam-user/components/09-logon.js:49:32)
      at Timeout._onTimeout (/var/www/app/dist/bot-client.js:233:28)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)
} Error: Already attempting to log on, cannot log on again
    at SteamUser.logOn (/var/www/app/node_modules/steam-user/components/09-logon.js:49:32)
    at Timeout._onTimeout (/var/www/app/dist/bot-client.js:233:28)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

My current workaround is to check for this internal property on the SteamUser object, but it smells funny.

if (this.steamUser['_connecting']) return

I was able to reproduce this error by setting an extremely low proxy timeout (1ms) here: https://github.com/DoctorMcKay/node-stdlib/blob/master/src/lib/http/proxyagent.ts#L41

My guess is that the proxy timeout aren't being handled in the same way as vanilla WS timeouts, because they emit an error instead of timeout.

Versions

node v14 steam-user 5.0.8