django / asgi_ipc

IPC-based ASGI channel layer
BSD 3-Clause "New" or "Revised" License
37 stars 13 forks source link

Starting daphne causes ValueError: The size is invalid or the memory is read-only #19

Closed jstray closed 7 years ago

jstray commented 7 years ago

I get this every single time I try to start a server with daphne cjworkbench.asgi:channel_layer:

Traceback (most recent call last):
  File "/Users/jonathanstray/anaconda/lib/python3.5/site-packages/asgi_ipc.py", line 208, in __init__
    size=self.size,
ValueError: The size is invalid or the memory is read-only

And then several other exceptions while handling that one. This is on Mac OS. Maybe is mmap not supported on this OS?

My settings:

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_ipc.IPCChannelLayer",
        "ROUTING": "cjworkbench.routing.channel_routing",
        "CONFIG": {
            "prefix": "cjworkbench",
        },
    },
}
andrewgodwin commented 7 years ago

The IPC layer requires both free memory and a compatible underlying UNIX system, so it's possible that either you have memory exhaustion or your version of Mac OS isn't quite compatible with how we're allocating it. Either way, I suggest you switch to the Redis backend.

thijsvandien commented 7 years ago

If OS X is listed as a supported platform, could we perhaps actually solve this issue? I'm experiencing the same on OS X 10.11.6 and found that instantiating SharedMemory with the O_CREAT flag does not, in fact, only try to create a segment if it doesn't exist yet. The second time it fails with either the given ValueError or a posix_ipc.PermissionsError. This might be a bug in posix_ipc, but it seems possible to work around it by changing:

self.memory = posix_ipc.SharedMemory(path, flags=posix_ipc.O_CREAT, size=self.memory_size)

into:

try:
    self.memory = posix_ipc.SharedMemory(path, flags=posix_ipc.O_CREX, size=self.memory_size)
except posix_ipc.ExistentialError:
    self.memory = posix_ipc.SharedMemory(path)

I then get an _pickle.UnpicklingError: invalid load key, '\x00'. I'm not sure why that (assumably) isn't an issue on Linux, but it's a matter of initialization that should be easy to fix. Edit: already fixed.