daphne icon indicating copy to clipboard operation
daphne copied to clipboard

Daphne 2.1.0 fails silently if the port is already in use

Open elros opened this issue 6 years ago • 10 comments

The same problem was fixed in version 1.4.0 (see #133), but seems like it reappeared with a subtle change.

Summary: If the port is already in use, daphne exits silently without output. (Even with debug verbosity parameter it still outputs nothing.)

Expected behaviour: Daphne should fail with an error message when the port is already in use.

elros avatar Apr 03 '18 10:04 elros

I can confirm this happens locally, but I have no idea why - something inside Twisted is not behaving as I would expect with endpoints (the fix from before is still in place). I won't have time to investigate further for a week or two, so if anyone wants to dig more and work out what's going on they are welcome.

andrewgodwin avatar Apr 06 '18 01:04 andrewgodwin

Which OS are you using? daphne==2.1.0 is working correctly on Ubuntu 18.04.

2018-05-17 20:00:20,451 INFO     Starting server at tcp:port=9000:interface=0.0.0.0
2018-05-17 20:00:20,453 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2018-05-17 20:00:20,454 INFO     Configuring endpoint tcp:port=9000:interface=0.0.0.0
2018-05-17 20:00:20,458 CRITICAL Listen failure: Couldn't listen on 0.0.0.0:9000: [Errno 98] Address already in use.

ChillarAnand avatar May 17 '18 14:05 ChillarAnand

I tried reproducing this, but with no success. I am using daphne==2.1.2 (have tested with 2.1.2, 2.1.1, 2.1.0 and 2.0.0) on Ubuntu 16.0.4. I get the same messages as @ChillarAnand :

$ daphne -p 8000 -b 127.0.0.1 testproj.routing:channel_layer
2018-05-26 13:13:52,591 INFO     Starting server at tcp:port=8000:interface=127.0.0.1
2018-05-26 13:13:52,591 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2018-05-26 13:13:52,591 INFO     Configuring endpoint tcp:port=8000:interface=127.0.0.1
2018-05-26 13:13:52,592 CRITICAL Listen failure: Couldn't listen on 127.0.0.1:8000: [Errno 98] Address already in use.

I've tried with different routers. Both manage.py runserver and calling daphne directly work for me (although note that using manage.py runserver will not quit, just wait for file changes and restart then).

There are a few possible ways how this could happen, when the setup for Twisted is changed in specific ways; but I can't see how that could be reached. @elros could you please post some more information, your configuration, your system etc, on how we can reproduce this?

spielmannj avatar May 26 '18 11:05 spielmannj

It's just happened to me as well, but in my case it was a root Django logger that sent all messages above ERROR to some other handler (Sentry). daphne CLI uses logging to display errors, not stderr. When I reconfigured the logger to also write messages to the console, I started seeing the errors. Also, daphne always exits with status code 0, even in case of an error. Which is an inconvenience if you start it from a batch file for example.

mizi avatar Jul 12 '18 20:07 mizi

Did u find the solution? I am getting the same prob.

saibhaskar24 avatar Jul 16 '20 05:07 saibhaskar24

@saibhaskar24 — We still need a reproduce... — Ideally a minimal project showing the issue.

carltongibson avatar Jul 16 '20 06:07 carltongibson

I have raised an issue in statckoverflow and after that I found this issue : https://stackoverflow.com/q/62926804/9797207

saibhaskar24 avatar Jul 16 '20 06:07 saibhaskar24

@carltongibson Facing same issue! Can I share my project SSH login to your email!?

samarkhanp avatar Jul 16 '20 06:07 samarkhanp

Hi @saibhaskar24 @samarkhanp — Sorry, I can't debug your server for you.

What we need is a minimal sample project that demonstrates the issue. Or exact reproduce steps to recreate it.

carltongibson avatar Jul 16 '20 06:07 carltongibson

@carltongibson can I add you as contributer to my project as that is private?

But I think I don't have any prob with project.

As daphne -p 8005 -b 0.0.0.0 myproject.asgi:application is working fine.

And even the sockets connection is good.

I have already kept the configuration in the statckoverflow issue.

saibhaskar24 avatar Jul 16 '20 06:07 saibhaskar24

I'm going to close this as stale. If someone can provide a reproduce against Daphne 4.0 (with the latest Twisted) in a fresh ticket I'm happy to have a look.

carltongibson avatar Oct 07 '22 13:10 carltongibson