Channels: 503 Service Unavailable

Created on 14 Apr 2016  路  11Comments  路  Source: django/channels

I've just upgraded to the latest version 0.11.0 (via pip) of channels.

After the first request, the server hangs and I get this:

503 Service Unavailable
Worker server failed to respond within time limit.
Daphne

The upgrade was prompted by the login to admin issue, which I believe was something to do with cookies being passed incorrectly.

I also get this message intermittently:

Traceback (most recent call last):
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/channels/management/commands/runserver.py", line 82, in inner_run
http_timeout=60,  # Shorter timeout than normal as it's dev
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/daphne/server.py", line 49, in run
reactor.run(installSignalHandlers=self.signal_handlers)
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/twisted/internet/base.py", line 1194, in run
self.mainLoop()
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/twisted/internet/base.py", line 1203, in mainLoop
self.runUntilCurrent()
<exception caught here> 
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/twisted/internet/base.py", line 825, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/daphne/server.py", line 69, in backend_reader
self.factory.dispatch_reply(channel, message)
File "/Users/chris/Projects/flik/env_flik/lib/python3.4/site-packages/daphne/http_protocol.py", line 252, in dispatch_reply
unknown_message_keys,
builtins.ValueError: Got invalid WebSocket reply message on websocket.send!kduIogea - contains unknown keys {'reply_channel', 'path', 'order'}

pip install daphne==0.10.2 --upgrade

Seems to have resolved it for now

Most helpful comment

The worker/daphne split is covered in the docs: http://channels.readthedocs.io/en/latest/deploying.html#run-worker-servers

Basically you need to either:

  • Run runserver
  • Run daphne and runworker

Also if you want to use Redis on Windows, Microsoft maintain a lovely port: https://github.com/MSOpenTech/redis

All 11 comments

What version did you have of daphne when you got this error? There was a change recently where the protocol they talk over changed; before 1.0, I'd recommend upgrading them both at the same time (along with asgi_redis and asgiref)

0.10.3

I did try completely stripping down and rebuilding my virtualenv, and the problem persisted. But this is a fairly complex project, with a fair number of dependencies. I've just gone back up to 0.10.3 and it seems stable for now. I'll report back if it starts breaking again. It seemed fairly consistent, and I was upgrading using

pip install channels --upgrade

Is that the correct procedure, or should I be doing something specific with daphne as well?

The problem started happening as soon as I went back up to 0.10.3:

Got invalid WebSocket reply message on websocket.send!gyhygXrH

And the server is hanging again.

Ah, I think I might know what this is. What are you sending as a reply down the websocket? Are you just round-tripping the receive message? I added a check to make sure websocket reply messages only contained the keys "text", "bytes" and "close", as people were sending dicts down assuming they'd serialise, so it's possible you were sending more down and the upgrade has started catching that.

Ah, this makes perfect sense, I've been doing some very in-out type handlers, so I assume this is the problem. I'll report back ASAP once I can confirm.

Closing due to inactivity.

daphne==0.15.0 response error 503 too.
where is the problem?!

It's likely you don't have a worker server running?

simply i get confused on how to use channels & don't know how to run workers? shall i run workers & runserver both?! (as i am new in web development so i don't know lots of basics. that's all about 3 month i started & as the first framework i use django with <3 ) i have read several pages on how to use django.channels & almost (means actually half of -_-) it's document, run the test sample chat room app locally ( as it was so hard cause the redis got's hard to handle on windows, and asgi_ipc that needs POSIX_IPC had wheel building problem while installation, how ever it works correctly on Linux ). the whole problem is i don't get how really it works?! is there any starter ( mean easier ) documents for me? how should i start on channels?
i need this for real time notifications, & tracking objects on map in next. started a simple app to make some real time notifications on my project but i don't know how to do...

The worker/daphne split is covered in the docs: http://channels.readthedocs.io/en/latest/deploying.html#run-worker-servers

Basically you need to either:

  • Run runserver
  • Run daphne and runworker

Also if you want to use Redis on Windows, Microsoft maintain a lovely port: https://github.com/MSOpenTech/redis

Using the microsoft port made redis work for me. Was trying to use another redis port, which had worked at one time, but had stopped. I recommend the Microsoft port. Thanks, Andrew!

Was this page helpful?
0 / 5 - 0 ratings