aiannacc / Goko-Salvager

Enhance your Dominion Online experience!
13 stars 9 forks source link

autokick/Goko race condition #216

Open aiannacc opened 10 years ago

aiannacc commented 10 years ago

I haven't been able to reproduce this problem on my own. This is speculation based on a bug report from hvb: http://forum.dominionstrategy.com/index.php?topic=8163.msg373261#msg373261

This is the offending line:

https://github.com/aiannacc/Goko-Salvager/blob/master/src/ext/autokick.js#L33

The problem is that Goko's mtgRoom.helpers.RatingHelper._rankingsCached object sometimes doesn't get populated quickly enough. If an opponent joins your game before it does, you get an exception that interferes with the ordinary Goko client functionality.

Probably we need to check if the cache is available and run the async queries to request the joiner's Goko Pro rating if it isn't. I really hate writing and reading that sort of callback spaghetti, but it's not quite so horrible if we implement it with JS Promises.

Note that Goko has its own proprietary Promise-like API. Most of the queries called on a FS.Connection object generate these FunSockets "Promise" objects. It's worse, than the official JS Promise API though... you can't chain then() or except() methods and there are some other gotchas.