Forums

ASGI CRITICAL Listen failure

Hello! I have been using pythonanywhere for a while now, and I've been trying to follow a tutorial for a live chat between users. The tutorial uses ASGI, and I've been looking online, and I saw that Pythonanywhere did support it, albeit in beta. I tried to get it set up, and after many headaches, I managed to get it to actually read the ASGI files. But now I have a new error, where anytime I try to start up the server, I get this error:

2025-08-27 10:41:57,440 INFO     Starting server at unix:/var/sockets/dworks.pythonanywhere.com/app.sock
2025-08-27 10:41:57,487 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2025-08-27 10:41:57,488 INFO     Configuring endpoint unix:/var/sockets/dworks.pythonanywhere.com/app.sock
2025-08-27 10:41:57,489 CRITICAL Listen failure: Couldn't listen on any:b'/var/sockets/dworks.pythonanywhere.com/app.sock': Cannot acquire lock.

I am by no means a coding expert, so I don't know what's going on. I've tried reloading the website, I've checked the console page and confirmed that no processes were running, and I've even tried deleting it and then using "pa website create" to get it back up, but it still won't work. I don't know who else to ask for help. I realize that ASGI is in beta, and it might be because of that, or maybe I'm setting something up wrong? I'm not very well versed in these types of things at all. I am using Django, with daphne, if that's helpful, and if there are any files you need to help troubleshoot, I'm happy to provide them. Please let me know if you guys can help. Thanks!

Try pa website delete first and then re-create it with pa website create and tell what you see.

Thank you for the advice, however, it didn't work, sadly. I'm still getting the same error message:

2025-08-28 09:07:25,391 INFO     Starting server at unix:/var/sockets/dworks.pythonanywhere.com/app.sock
2025-08-28 09:07:25,391 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2025-08-28 09:07:25,392 INFO     Configuring endpoint unix:/var/sockets/dworks.pythonanywhere.com/app.sock
2025-08-28 09:07:25,394 CRITICAL Listen failure: Couldn't listen on any:b'/var/sockets/dworks.pythonanywhere.com/app.sock': Cannot acquire lock.

I've tried everything I can think of. The Google AI suggests that maybe I still have a process running, and to use pa website reload and kill all the processes on the console page, but that doesn't do anything either. I'm thinking either there is some invisible project running with an error, or that maybe there's something I don't have the permissions to edit. The command I'm using is pa website create --domain dworks.pythonanywhere.com --command '/home/Dworks/.virtualenvs/my-asgi-venv/bin/daphne --u ${DOMAIN_SOCKET} Y.social.social.asgi:application' and the tutorial I'm following is this youtube link. I don't know if this helps at all but I figured it might? Thank you so much for helping.

Actually, now that I look, I'm not seeing a /var/sockets/ folder. Could that be the issue? Is it trying to read a file that doesn't exist?

You wouldn't have access to this file. Could that be the issue that in your command you use --u instead of -u?

Thanks for the suggestion. I tried it, but it didn't work. This is really confusing. The Google AI thing said something else might be using the Unix port, but I'm pretty sure that there isn't something there. Maybe it's something wrong with my consumers.py or my asgi.py? I don't think so but if you need any of my files I'd be happy to give them to you :D

Okay, update!

I changed my command to /home/Dworks/.virtualenvs/my-asgi-venv/bin/daphne -u /var/sockets/dworks.pythonanywhere.com/app1.sock Y.social.social.asgi:application

And I got:

2025-08-28 14:15:09,567 INFO     Starting server at unix:/var/sockets/dworks.pythonanywhere.com/app1.sock
2025-08-28 14:15:09,604 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2025-08-28 14:15:09,613 INFO     Configuring endpoint unix:/var/sockets/dworks.pythonanywhere.com/app1.sock
2025-08-28 14:15:16,075 INFO     Killed 0 pending application instances

Thank you for all of your help! I'm pretty sure that this fixed it. I'll tell you if something else messes up. :)

The only issue I have now is I keep getting a 502 when I try and load the website. I think that's a "my code" problem, though. Only thing is, I'm not seeing any error messages.

I think you should use ${DOMAIN_SOCKET} rather than some string here. I've just checked and was able to start a basic ASGI app with daphne, so it should be possible to run it on PythonAnywhere.

Whenever I do ${DOMAIN_SOCKET} I get the CRITICAL Listen failure message. I think that the 502 error I'm getting is my code's problem. Here's what I'm seeing:

502 Bad Gateway Error

This is not your typical pythonanywhere error message, so I'm thinking that this is a simple case of me configuring something wrong. I'm using the string instead of the variable because they lead to the same place, with the only difference being that I'm not trying to connect to the dworks.pythonanywhere.com/app.sock, which has a broken lock. I'm generating a new one under app1 to avoid the error message, and it appears to be working. I'm pretty sure I just have some weird typo in either my settings or my asgi.py. If I have anymore questions, I'll be sure to let you guys know. I think I'm going to go through and check all of my code for typos and such. Thank you so much for helping me, I really appreciate it.

So, what is the shape of your final working command?

pa website create --domain dworks.pythonanywhere.com --command '/home/Dworks/.virtualenvs/my-asgi-venv/bin/daphne -u /home/Dworks/Y/social/app.sock Y.social.social.asgi:application'

I moved the socket to a directory that I can easily access, just so that I can see what file gets corrupted in the case of the lock not found error I was getting.

You cannot move the socket. It needs to be in the specific location so the server can find it. Daphne does some weird stuff with the socket, so it does sometimes start up, but reloading the app will not work. There are also other issues with Daphne. As part of completing the work on ASGI web apps we will fix those but, at the moment, Daphne will not work on PythonAnywhere.