django / asgi_ipc

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

Unlink shared memory when MemoryDatastructure instances are destroyed. #7

Closed eldritchideen closed 7 years ago

eldritchideen commented 8 years ago

While running the test suite for asgi_ipc multiple times in a row, it would start failing with the following exception.

Traceback (most recent call last): File "/Users/sjc/anaconda3/envs/channel-dev/lib/python3.5/unittest/loader.py", line 428, in _find_test_path module = self._get_module_from_name(name) File "/Users/sjc/anaconda3/envs/channel-dev/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name __import__(name) File "/Users/sjc/projects/python/channels/asgi_ipc/test_asgi_ipc.py", line 9, in <module> class IPCLayerTests(ConformanceTestCase): File "/Users/sjc/projects/python/channels/asgi_ipc/test_asgi_ipc.py", line 11, in IPCLayerTests channel_layer = IPCChannelLayer(expiry=1, group_expiry=2, capacity=5) File "/Users/sjc/projects/python/channels/asgi_ipc/asgi_ipc.py", line 43, in __init__ self.channel_store = MemoryDict("/%s-chan" % self.prefix, size=channel_memory) File "/Users/sjc/projects/python/channels/asgi_ipc/asgi_ipc.py", line 213, in __init__ "Error was: %s" % e ValueError: Unable to allocate shared memory segment (potentially out of memory). Error was: The size is invalid or the memory is read-only

Tracked this down to the shared memory segment not being marked for release once the last process has unattached from it. The fd is closed, but the segment is never unlinked.

Adding a call to the unlink() method on the SharedMemory instance, in __del__ results in being able to run the unit tests continuously without failing after an initial run.