Bug - Fixed Mafia does not always logout correctly when quitting.

xKiv

Active member
When I choose "exit kolmafia" from the menu, often time mafia doesn't perform logout actions correctly (obvious workaround: manual logout before quitting).
I noticed this because data in my data/xkiv_turns_spent.ser was obviously wrong (several hundreds of turns lower, or all zeroes).

Debugging only leaves me confused, because it looks like *every* thread is trying to quit and logout.

Part of it is probably that LogoutManager.logout only cares about logout running right now, when maybe it should care about whether I am logged in our out. Time it rightly wrong, and every thread does, effectively
Code:
if (!LogoutManager.isRunning) {
 LogoutManager.isRunning = true;
 doLogout();
 LogoutManager.isRunning = false;
}
And it's not even synchronized, so in a different wrong timing, all thread can finish the if(!isRunning), and *then* call doLogout in parallel. Even if isRunning was volatile (which I am not sure if it needs to be, if the test is in a synchronized block; maybe it should anyway? I don't know what the optimizer is allowed to break inside synchronized blocks ... it's definitely allowed to break things outside them)

So, for example, now I have seen my data/xkiv_turns_spent.ser being overwritten at least 8 times already, and most of them overwrote it with empty data (presumably because another thread already finished logging out and resetting everything).
 

xKiv

Active member
Actually, my original problem seemed to be that the logout just doesn't happen at all (the serialized file was several days old, and a breakpoint placed in the serialization method was never triggered, and the quit was suspiciously fast. But I couldn't reproduce that with detailed debugging - instead I reproduced a different problem with similar (and perhaps even worse) symptoms.
 

fronobulax

Developer
Staff member
I have noticed (warning - anecdotes only) things that made me think something with logout was not right. I specifically noted the absence of the message about updating mall prices for all three characters today. Because of circumstances I could not confirm that the logout script had run or not. Subjectively KoLmafia seemed to shut down faster. I typically use the Exit option from the menu.
 

Veracity

Developer
Staff member
I wonder if this has something to do with the change I made recently which stopped making a Login frame when you select Quit from the menu?

(I never exit that way; I close windows back to the Login Frame and then close that window.)
 

Veracity

Developer
Staff member
Looks like it. Revision 15951 reverts that particular change.

I don't like it, but obviously I don't understand why we run a Logout thread when the last frame closes (even if we are already exiting) - and why I ended up with a dozen such threads running in parallel...
 

fronobulax

Developer
Staff member
I saw the expected messages during logout with r15951 so I would say the behavior is back to what I expect.
 

xKiv

Active member
Oh. Is it possible that this is because, without the login frame, messages have nowhere to go?
 
Top