mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #700] gallery: disable Windows port double-bind, report bound --port 0 URL, and close socket in finally (GALLERY-PORT-BIND-AND-URL) #742
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#742
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/700
Author: @kirigayakazima
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/gallery-port-bind-and-url📝 Commits (1)
f690f3dgallery: disable Windows port double-bind, report bound --port 0 URL, and close socket in finally📊 Changes
2 files changed (+112 additions, -13 deletions)
View changed files
📝
tests/test_gallery.py(+95 -0)📝
tools/gallery.py(+17 -13)📄 Description
Claimed in the coordination issue as: GALLERY-PORT-BIND-AND-URL https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131322740
What and why
Fixes three listening-socket and lifecycle bugs in
tools/gallery.py(start_server):allow_reuse_address = os.name != "nt"): Just likeViewerServerinviewer/serve.py,http.server.HTTPServerdefaults toallow_reuse_address = True. On Windows,SO_REUSEADDRlets a secondThreadingServerbind a port that another gallery instance is already actively listening on instead of raisingOSError— silently breaking bothGalleryListenErrorreporting and default--port(8080->8081) fallback.--port 0(httpd.server_port):start_serverbuilt the printed URL and browser launch target fromaddr[1]instead ofhttpd.server_port, printing and openinghttp://localhost:0when--port 0asked the OS for an ephemeral port.try ... finally: httpd.server_close()): Movedhttpd.server_close()into afinallyblock covering banner printing,webbrowser.open(url), andhttpd.serve_forever(), so the listening socket closes cleanly on normal return or error as well asKeyboardInterrupt.Adds 3 regression tests in
tests/test_gallery.py(using real loopback sockets and synthetic empty temp dirs; no game files) and closes the mockedserver_closeintest_implicit_port_can_use_the_next_port.Tested
Windows 11 x64, Python 3.14.7, CPU only, synthetic assets only (no game files). Commit
f690f3d501a218e8c23545d6932e50deb01c9ba4.python -I -W error::ResourceWarning tests/test_gallery.py -v:main(21625bca) with only the 3 new tests: all 3 new tests fail (AssertionError: 0 not greater than 0,AssertionError: GalleryListenError not raised,AssertionError: Lists differ: [] != [-1]);python -I tests/test_ci_registration.py: 15 tests, OK.python -I tests/test_text_write_line_endings.py: 3 tests, OK.python -I scripts/check_no_game_data.py tools/gallery.py tests/test_gallery.py,python -m compileall -q tools tests,git diff --check: clean (exit0).GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.