Skip to content

Commit b5913cc

Browse files
Berserker66qwint
authored andcommitted
WebHost: fix AutoLauncher restarting rooms due to race condition (ArchipelagoMW#3333)
1 parent 9fa0825 commit b5913cc

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

WebHostLib/autolauncher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def keep_running():
8080
room.last_activity >= datetime.utcnow() - timedelta(days=3))
8181
for room in rooms:
8282
# we have to filter twice, as the per-room timeout can't currently be PonyORM transpiled.
83-
if room.last_activity >= datetime.utcnow() - timedelta(seconds=room.timeout):
83+
if room.last_activity >= datetime.utcnow() - timedelta(seconds=room.timeout + 5):
8484
hosters[room.id.int % len(hosters)].start_room(room.id)
8585

8686
except AlreadyRunningException:

WebHostLib/customserver.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor, load_server_cert
2323
from Utils import restricted_loads, cache_argsless
24-
from .locker import Locker
2524
from .models import Command, GameDataPackage, Room, db
2625

2726

@@ -246,25 +245,24 @@ async def start_room(room_id):
246245
ctx.shutdown_task = asyncio.create_task(auto_shutdown(ctx, []))
247246
await ctx.shutdown_task
248247

249-
# ensure auto launch is on the same page in regard to room activity.
250-
with db_session:
251-
room: Room = Room.get(id=ctx.room_id)
252-
room.last_activity = datetime.datetime.utcnow() - datetime.timedelta(seconds=room.timeout + 60)
253-
254248
except (KeyboardInterrupt, SystemExit):
255-
with db_session:
256-
room = Room.get(id=room_id)
257-
# ensure the Room does not spin up again on its own, minute of safety buffer
258-
room.last_activity = datetime.datetime.utcnow() - datetime.timedelta(minutes=1, seconds=room.timeout)
249+
pass
259250
except Exception:
260251
with db_session:
261252
room = Room.get(id=room_id)
262253
room.last_port = -1
263-
# ensure the Room does not spin up again on its own, minute of safety buffer
264-
room.last_activity = datetime.datetime.utcnow() - datetime.timedelta(minutes=1, seconds=room.timeout)
265254
raise
266255
finally:
267-
rooms_shutting_down.put(room_id)
256+
try:
257+
with (db_session):
258+
# ensure the Room does not spin up again on its own, minute of safety buffer
259+
room = Room.get(id=room_id)
260+
room.last_activity = datetime.datetime.utcnow() - \
261+
datetime.timedelta(minutes=1, seconds=room.timeout)
262+
logging.info(f"Shutting down room {room_id} on {name}.")
263+
finally:
264+
await asyncio.sleep(5)
265+
rooms_shutting_down.put(room_id)
268266

269267
class Starter(threading.Thread):
270268
def run(self):

0 commit comments

Comments
 (0)