Jump to content
McKay Development
Sign in to follow this  
E46

SteamUser class won't get cleared from memory after error event

Recommended Posts

Hello,

What is the proper way to remove/clear a steamUser class from memory after it has run into the error event?

If the logOn(); was successful and I call the logOff() and then delete the var it seems to get cleared properly or picked up by the GC at least. with an error this doesn't seem the case and hangs around in the memory forever. (tested with --inspect)

(I know delete might not work if it is referenced somewhere else but its not. Also I understand that it won't get cleared instantly but might be picked up by the garbage collector correct? but even after leaving it idle for a long time afterwards with no running bots the steamUser in the memory never gets cleared)

Or am I doing something obviously wrong in the code? Any help would be appreciated.


SteamUser: 4.13.2
NodeJS: v12.16.1

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


var activeBots = {};


var botOptions = {
	promptSteamGuardCode: false,
	singleSentryfile: false,
	autoRelogin: true,
	//localAddress: '',
	dataDirectory: null,
};


function createBot(steamUsername, steamPassword) {
    var bot = new SteamUser(botOptions);

    /*
    *	Bot Functions
    */
	bot.steamLogin = function () {
		bot.logOn({ 
			'accountName': steamUsername,
			'password': steamPassword,
		});
	}

    /*
    *	Bot Events
    */
    bot.on('loggedOn', function(details) {
    	log('loggedOn successful', steamUsername);

		bot.gamesPlayed([730]); // csgo

    	log('loggedOn gamesPlayed successful', steamUsername);
    });


    bot.on('error', function(err) {
    	switch(err.eresult) {
    		case 5:
    			log('error: invalid password');
    		case 84:
    			log('error: rate limit exceeded');
    		case 6:
    			log('error: logged in elsewhere');
    		default:
    			log('error: ' + err.eresult, steamUsername);
    	}

    	// stop bot on any error
    	stopBot(steamUsername);
    });


	return bot;
}




function startBot(steamUsername, steamPassword) {
	activeBots[steamUsername] = createBot(steamUsername, steamPassword);
	activeBots[steamUsername].steamLogin();
}

function stopBot(steamUsername) {
	if(typeof activeBots[steamUsername] !== 'undefined' && activeBots[steamUsername]) {
	    //await activeBots[steamUsername].logOff(); // logOff is not async function?

	    activeBots[steamUsername].logOff(); // logout, but if the bot ran into an error its not logged in
	    delete activeBots[steamUsername]; // seems to work, but not if it ran into an error

	    log('bot stopped', steamUsername);
	}
}

/*
*	Logging
*/
function log(message, steamUsername = false) {
	if (steamUsername) {
		console.log('[' + steamUsername + '] ' + message);
	} else {
		console.log(message);
	}
}






// testing
runTest1();

async function runTest1() {
	startBot('', '');
	await sleep(5000);
	stopBot('');
	await sleep(200000);
}



function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}


console.log('end of file');

 

Edited by E46

Share this post


Link to post
Share on other sites

I don't see any reason why that should be the case. The only reason I could figure that would happen is that it doesn't clean up some timer or something, but every instance where it emits error, it also calls _disconnect, which cleans up after itself.

Do you know what particular error code(s) cause this?

Share this post


Link to post
Share on other sites
19 hours ago, Dr. McKay said:

I don't see any reason why that should be the case. The only reason I could figure that would happen is that it doesn't clean up some timer or something, but every instance where it emits error, it also calls _disconnect, which cleans up after itself.

Do you know what particular error code(s) cause this?

 

 

Might be an issue with my code actually. This is what I've got currently as start/stop function:

function startBot(steamUsername, steamPassword) {
	if(typeof activeBots[steamUsername] !== 'undefined' && activeBots[steamUsername]) {
		stopBot(steamUsername);
	}

	activeBots[steamUsername] = createBot(steamUsername, steamPassword);
	activeBots[steamUsername].steamLogin();
}

function stopBot(steamUsername) {
	if(typeof activeBots[steamUsername] !== 'undefined' && activeBots[steamUsername]) {
	    activeBots[steamUsername].logOff(); // logout
	    delete activeBots[steamUsername]; // clear memory?
	    log('bot stopped', steamUsername);
	}
}

 

 

When I run a test like this, it always seem to leave the SteamUser class in memory forever,  Even though they exit with error 34:

async function runTest1() {
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account1', '');
	startBot('account2', '');
	startBot('account3', '');
	await sleep(30000);
	stopBot('account1');
	stopBot('account2');
	stopBot('account3');
	await sleep(200000);
}

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...