django / asgi_ipc

IPC-based ASGI channel layer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running channels as non-root user gives "posix_ipc.PermissionsError: Permission denied"

dimon777 opened this issue · comments

I am getting "posix_ipc.PermissionsError: Permission denied" when running channels example as non-root user:

$ python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f693358e158>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/channels/management/commands/runserver.py", line 38, in inner_run
    self.channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER]
  File "/usr/local/lib/python3.5/dist-packages/channels/asgi.py", line 53, in __getitem__
    self.backends[key] = self.make_backend(key)
  File "/usr/local/lib/python3.5/dist-packages/channels/asgi.py", line 44, in make_backend
    asgi_layer = backend_class(**self.configs[name].get("CONFIG", {}))
  File "/usr/local/lib/python3.5/dist-packages/asgi_ipc.py", line 43, in __init__
    self.channel_store = MemoryDict("/%s-chan" % self.prefix, size=channel_memory)
  File "/usr/local/lib/python3.5/dist-packages/asgi_ipc.py", line 201, in __init__
    initial_value=1,
posix_ipc.PermissionsError: Permission denied
^CException ignored in: <bound method MemoryDatastructure.__del__ of <asgi_ipc.MemoryDict object at 0x7f6933590630>

It tries to use /asgi-chan path for Semaphore and promptly fails. This error doesn't happen when running as root user. Please see line 43 and 45 in asgi_ipc.py

Permissions on the root path do not correlate to actual filesystem permissions; I can run it as a non-root user perfectly fine under Ubuntu 16.04. What OS/distro are you using?

I was getting the same error trying to run daphne as www-data. Using strace revealed the root cause : I had previously run daphne as another user, and as a result the entries in /dev/shm/ were owned by that other user.

Maybe those entries need to be cleaned up when the process exits?

Ah, that would explain it. Shared memory segments usage is going away in asgi_ipc as of next release anyway, to be replaced with SQLite on disk (#22), so cleanup/permission errors for that should be a lot better. I'm going to close this ticket as shared memory will no longer be something we use and thus no errors can come from it.