0

daphne and Django channels work fine on command line or single process. But when I start it with supervisor, the error occurs.

2020-02-18 12:40:35,995 CRITICAL Listen failure: [Errno 88] Socket operation on non-socket

My config file is

[program:asgi]

socket=tcp://localhost:9000

directory=/root/test/test/

command=daphne -u /run/daphne/daphne%(process_num)d.sock --endpoint fd:fileno=0 --access-log - --proxy-headers test.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=2

# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d

# Automatically start and recover processes
autostart=true
autorestart=true

# Choose where you want your log to go
stdout_logfile=/root/test/test/script/asgi.log
redirect_stderr=true

[supervisord]
[supervisorctl]

Any ideas? Thanks!

2 Answers2

1

There seemed to be a bug with either Python or Twisted unable to bind to the file descriptor 0 as referenced here: https://github.com/django/daphne/issues/263

Try to bind the socket to another fd, say 10 like so: daphne -u /run/daphne/daphne%(process_num)d.sock --fd 10 --access-log - --proxy-headers test.asgi:application

If that doesn't work, try checking whether you have read and write access to the /run/daphne/ folder itself

Fireken
  • 118
  • 5
  • I am getting the same issues. I also tried with other values except 0 but still issue remains. Daphne works fine without using the --fd option. Is that recommended in production with multiple processes spawned by supervisor? – DancingJohn May 23 '20 at 06:11
  • I don't think that's recommended. What is interesting though, when I tried after restarting the server, setting the fd to 0 works. – Fireken May 29 '20 at 16:22
1

First line - [program:asgi]

Must be like this: [fcgi-program:asgi]

If you carefully study the documentation, it is obvious that the first line of the config is incorrect.

https://channels.readthedocs.io/en/stable/deploying.html#example-setups

Look carefully at the given config in the example`