Running a second server on the same port doesn't fail on Windows
vxgmichel opened this issue · comments
Vincent Michel commented
I noticed that starting the same server twice doesn't fail on Windows.
Here's the server I used to run the test:
import os
import asyncio
from quart import Quart
from hypercorn.asyncio import serve
from hypercorn import Config
app = Quart(__name__)
@app.route('/')
async def hello():
return f"{os.getpid()}"
if __name__ == "__main__":
config = Config()
asyncio.run(serve(app, config))
This is what happens on Linux:
$ python test_app.py
[2023-12-08 14:02:04 +0100] [41578] [INFO] Running on http://127.0.0.1:8000 (CTRL + C to quit)
# Simultaneously
$ python test_app.py
[...]
OSError: [Errno 98] Address already in use
And what happens on Windows:
$ python test_app.py
[2023-12-08 15:01:21 +0100] [2964] [INFO] Running on http://127.0.0.1:8000 (CTRL + C to quit)
$ python test_app.py
[2023-12-08 15:01:53 +0100] [6916] [INFO] Running on http://127.0.0.1:8000 (CTRL + C to quit)
Using a curl localhost:8000
shows that the first server answers the request, until it's killed. Then the next curl
requests are answered by the second server.
I ran a quick investigation and it seems related to this line, which is executed both on Windows and Linux:
hypercorn/src/hypercorn/config.py
Line 253 in 33ed006
Maybe this should be Linux only?
Phil Jones commented
Why should it fail?
Nathaniel J. Smith commented
Yeah `SO_REUSEADDR` on Windows is a trap. You basically _always_ want to
_enable_ on Unix and _always_ want to _disable_ it on Windows.
…On Tue, May 28, 2024 at 1:52 PM Phil Jones ***@***.***> wrote:
Reopened #171 <#171>.
—
Reply to this email directly, view it on GitHub
<#171 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEU42H5BWURQWFSQZZWO6DZETVCDAVCNFSM6AAAAABAMWTH32VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSHE3DGMBYHA4DSNQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Nathaniel J. Smith -- https://vorpus.org <http://vorpus.org>