SteamBot icon indicating copy to clipboard operation
SteamBot copied to clipboard

Occasionally fetching the schema fails and causes the bot to crash.

Open waylaidwanderer opened this issue 12 years ago • 13 comments

Here's what happens:

[Happy Bot 2013-07-23 17:10:06] ERROR: Unhandled exceptions in bot Happy Bot callback thread: 
 System.NullReferenceException: Object reference not set to an instance of an object
  at SteamTrade.Schema.FetchSchema (System.String apiKey) [0x00000] in <filename unknown>:0 
  at SteamBot.Bot.<HandleSteamMessage>b__77 (SteamKit2.LoginKeyCallback callback) [0x00000] in <filename unknown>:0 
  at SteamKit2.CallbackMsg.Handle[LoginKeyCallback] (System.Action`1 handler) [0x00000] in <filename unknown>:0 
  at SteamBot.Bot.HandleSteamMessage (SteamKit2.CallbackMsg msg) [0x00000] in <filename unknown>:0 
  at SteamBot.Bot.BackgroundWorkerOnDoWork (System.Object sender, System.ComponentModel.DoWorkEventArgs doWorkEventArgs) [0x00000] in <filename unknown>:0 
  at System.ComponentModel.BackgroundWorker.OnDoWork (System.ComponentModel.DoWorkEventArgs e) [0x00000] in <filename unknown>:0 
  at System.ComponentModel.BackgroundWorker.ProcessWorker (System.Object argument, System.ComponentModel.AsyncOperation async, System.Threading.SendOrPostCallback callback) [0x00000] in <filename unknown>:0 

Is there any way to avoid this? Perhaps by throwing a try-catch around it? That would probably work as an interim method, but perhaps there's a more elegant solution.

waylaidwanderer avatar Jul 23 '13 19:07 waylaidwanderer

Here's what I did for my bots. Might not be the best, but it works. I modified my bots to only get one schema in Program.cs and share it so this probably won't work on the real SteamBot, but you get the concept of it.

    if (MasterSchema == null)
    {
        MasterSchema = null;
        Console.WriteLine("Downloading schema...");
        while (MasterSchema == null)
        {
            try
            {
                MasterSchema = Schema.FetchSchema(configObject.ApiKey);
            }
            catch (Exception)
            {
                MasterSchema = null;
                Console.WriteLine("Problem while getting the schema.  Retrying in 10 seconds...");
                Thread.Sleep(10000);
            }
        }
        Console.WriteLine("Downloaded schema!");
    }

Jessecar96 avatar Jul 24 '13 01:07 Jessecar96

It will work, you just have to change the variable names because I changed some for the ScrapTF version.

Jessecar96 avatar Jul 26 '13 19:07 Jessecar96

Jesse you need some mutexes or locks up in this bitch

geel9 avatar Jul 26 '13 19:07 geel9

The current SteamBot does have a mutex for downloading the schema. Adding in a retry as @Jessecar96 suggested sounds good though.

waylaidwanderer avatar Jul 26 '13 22:07 waylaidwanderer

Last I checked you guys were trying some file lock shit

geel9 avatar Jul 26 '13 22:07 geel9

@geel9 It's a mutex. The lock file mess didn't work IIRC.

cwhelchel avatar Jul 28 '13 03:07 cwhelchel

I haven't run into this error for a while now.

waylaidwanderer avatar Jan 30 '14 00:01 waylaidwanderer

I thought it was resolved. Perhaps it needs to be more robust in general?

cwhelchel avatar Jan 30 '14 15:01 cwhelchel

I changed the behaviour of the schema fetching to use the modified since header and if there's any issues with the API it loads the local schema if present.

https://github.com/StormReaper/SteamBot/commit/4c6dd1f8144e66ac3bb3e7a479fe10743b797cb8

StormReaper avatar Feb 12 '14 23:02 StormReaper

This issue is mainly present with CSGO. Those api's are offline every other day. @Jessecar96 that fixed it, thanks.

Cyb3r16 avatar Sep 29 '14 16:09 Cyb3r16

You could make it so that the Schema retrieves the last cache whenever it encounters a WebException, by changing Schema.FetchSchema() and Schema.GetSchemaString(). That way, it will only crash if there is no schema file cached when the schema server is down.

Pastebin link to those two methods

I can't submit a PR as my fork of this repository is just for personal use (and tweaks). Could somebody test the changes above to see if they work on their own?

einsteinsci avatar Nov 07 '15 05:11 einsteinsci