Skip to content

Commit 208a0c6

Browse files
committed
WebHost: prevent infinite spinup loop of Rooms
1 parent c3c1ce5 commit 208a0c6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

WebHostLib/customserver.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,12 @@ async def main():
184184

185185
from .autolauncher import Locker
186186
with Locker(room_id):
187-
asyncio.run(main())
187+
try:
188+
asyncio.run(main())
189+
except:
190+
with db_session:
191+
room = Room.get(id=room_id)
192+
room.last_port = -1
193+
# ensure the Room does not spin up again on its own, minute of safety buffer
194+
room.last_activity = datetime.datetime.utcnow() - datetime.timedelta(minutes=1, seconds=room.timeout)
195+
raise

WebHostLib/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Room(db.Entity):
2929
show_spoiler = Required(int, default=0) # 0 -> never, 1 -> after completion, -> 2 always
3030
timeout = Required(int, default=lambda: 2 * 60 * 60) # seconds since last activity to shutdown
3131
tracker = Optional(UUID, index=True)
32+
# Port special value -1 means the server errored out. Another attempt can be made with a page refresh
3233
last_port = Optional(int, default=lambda: 0)
3334

3435

WebHostLib/templates/hostRoom.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
The server for this room will be paused after {{ room.timeout//60//60 }} hours of inactivity.
2121
Should you wish to continue later,
2222
anyone can simply refresh this page and the server will resume.<br>
23-
{% if room.last_port %}
23+
{% if room.last_port == -1 %}
24+
There was an error hosting this Room. Another attempt will be made on refreshing this page.
25+
The most likely failure reason is that the multiworld is too old to be loaded now.
26+
{% elif room.last_port %}
2427
You can connect to this room by using <span class="interactive"
2528
data-tooltip="This means address/ip is {{ config['PATCH_TARGET'] }} and port is {{ room.last_port }}.">
2629
'/connect {{ config['PATCH_TARGET'] }}:{{ room.last_port }}'
2730
</span>
28-
in the <a href="{{ url_for("tutorial_landing")}}">client</a>.<br>{% endif %}
31+
in the <a href="{{ url_for("tutorial_landing")}}">client</a>.<br>
32+
{% endif %}
2933
{{ macros.list_patches_room(room) }}
3034
{% if room.owner == session["_id"] %}
3135
<form method=post>

0 commit comments

Comments
 (0)