Bug hunting in the world of National Teams

A few weeks ago, we started investigating a bug regarding the team spirit (TS) updates of the National Teams. Users had realised that the TS drop in these updates were faster than usual. At first sight the updates seemed to be working fine, however after some time we discovered that once a week, during the Sunday update, something fishy happened. On Sundays, the code would either be triggered twice (leading to two team spirit updates, one after the other) or to no update at all. 


Now, the team spirit update is applied to all teams at once, so there was never any case that some National Teams had a missed daily update while others had a double drop. 


Finding and fixing this bug was made extra tricky by the fact that it only happened once a week, which reduced the number of chances we had to study it. In any case, the bug was easy to fix once the cause was found and since last week, the team spirit updates have been problem-free.


So, why this long post then? The matter is already resolved. Well, we simply thought the source of the problem was so funny, that we couldn’t keep it to ourselves!


Several years ago, we had the idea to create a feature that would include cash funds in the National Teams. As we do with most of our plans, we implemented part of it to see it in action. In the end, we weren’t satisfied with it. We never introduced the feature to the game, and we never mentioned it to the community as a potential addition. However, we did left our experimental code around, and it kept keeping a tally of the National Team cash as part of our weekly economy updates.


Guess what? Every Sunday, together with the team spirit update, all National Teams had a “secret” financial update. The wealthiest team had more than 2 billion SEK in their funds ready to spend on “not-implemented” features! For those of you that are not techie guys or gals, databases have a limit on integers, which means they cannot easily handle numbers that have a value higher than 2^31, or, to be more specific, higher than 2,147,483,647.


The result of this fantastical wealth was an arithmetic overflow that caused the update to either run twice or to just stop without running at all!


Now order is restored and austerity once again rules in the world of Hattrick national teams.