Skip to content

Commit da07f9e

Browse files
author
Delta-Kronecker
committed
fix: honor 5s stopping period when user stops mid-race, prevent stale stop timer from stomping next session
1 parent 68de53a commit da07f9e

1 file changed

Lines changed: 46 additions & 16 deletions

File tree

scripts/TorJetUi.cs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,13 +1320,16 @@ private void SessionWorker(int mode, int strategy, bool raceStart)
13201320
}
13211321
else
13221322
{
1323-
sessionBusy = false;
1324-
UiInvokeDelegate(delegate
1323+
if (!stoppingBusy)
13251324
{
1326-
bootPct = 0;
1327-
SetState(RunState.Idle);
1328-
FlashMessage("No cached connection");
1329-
});
1325+
sessionBusy = false;
1326+
UiInvokeDelegate(delegate
1327+
{
1328+
bootPct = 0;
1329+
SetState(RunState.Idle);
1330+
FlashMessage("No cached connection");
1331+
});
1332+
}
13301333
return;
13311334
}
13321335
}
@@ -1347,19 +1350,35 @@ private void SessionWorker(int mode, int strategy, bool raceStart)
13471350
uiRaceActive = false;
13481351
if (!ok)
13491352
{
1350-
sessionBusy = false;
1351-
UiInvokeDelegate(delegate
1353+
if (!stoppingBusy && !autoAbort)
13521354
{
1353-
bootPct = 0;
1354-
SetState(RunState.Idle);
1355-
FlashMessage(raceErr);
1356-
});
1355+
sessionBusy = false;
1356+
UiInvokeDelegate(delegate
1357+
{
1358+
bootPct = 0;
1359+
SetState(RunState.Idle);
1360+
FlashMessage(raceErr);
1361+
});
1362+
}
13571363
return;
13581364
}
13591365
mode = winnerMode;
13601366
lastWinnerMode = winnerMode;
13611367
if (autoLiveProc != null)
13621368
torProc = autoLiveProc; // winner kept alive — skip the restart
1369+
if (stoppingBusy)
1370+
{
1371+
// user asked to stop while the race was claiming the
1372+
// winner — don't bring the session up, let Disconnect
1373+
// drive the state back to Idle
1374+
if (autoLiveProc != null)
1375+
{
1376+
try { autoLiveProc.Kill(); } catch { }
1377+
autoLiveProc = null;
1378+
}
1379+
torProc = null;
1380+
return;
1381+
}
13631382
}
13641383
if (torProc == null)
13651384
{
@@ -1443,10 +1462,21 @@ private void Disconnect(string why)
14431462
Thread.Sleep(5000);
14441463
UiInvokeDelegate(delegate
14451464
{
1446-
bootPct = 0;
1447-
stoppingBusy = false;
1448-
SetState(RunState.Idle);
1449-
sessionBusy = false;
1465+
if (state == RunState.Stopping)
1466+
{
1467+
bootPct = 0;
1468+
stoppingBusy = false;
1469+
sessionBusy = false;
1470+
SetState(RunState.Idle);
1471+
}
1472+
else
1473+
{
1474+
// a newer session already took over (reconnect
1475+
// during the 5 s window) — release the stop flags
1476+
// without stomping its state or progress
1477+
stoppingBusy = false;
1478+
sessionBusy = false;
1479+
}
14501480
});
14511481
});
14521482
}

0 commit comments

Comments
 (0)