From f25b9f983132dc76d010a93dbc7a0d83a2d6c604 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 5 May 2021 13:29:55 -0700 Subject: [PATCH] Make the webconfig HTTP server threaded, fixing a Safari hang Recently Safari seems to hang with fish webconfig. This is apparently because Safari is opening a socket and not writing to it, causing webconfig to hang until the timeout (30 seconds). It's not clear why. Use ThreadingMixIn so that FishConfigTCPServer can handle more than one connection at a time. This fixes the hang under Safari. --- share/tools/web_config/webconfig.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index a71455972..f1890eb6e 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -865,7 +865,7 @@ class BindingParser: return readable_command + result -class FishConfigTCPServer(SocketServer.TCPServer): +class FishConfigTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): """TCPServer that only accepts connections from localhost (IPv4/IPv6).""" WHITELIST = set(["::1", "::ffff:127.0.0.1", "127.0.0.1"]) @@ -1575,6 +1575,11 @@ def runThing(): thread = threading.Thread(target=runThing) thread.start() +# Safari will open sockets and not write to them, causing potential hangs +# on shutdown. +httpd.block_on_close = False +httpd.daemon_threads = True + # Select on stdin and httpd stdin_no = sys.stdin.fileno() try: