Skip to content

Resource tracker fails to track filenames with colons on Linux #98896

Closed

Description

@maaleske

Bug report

multiprocessing.resource_tracker fails to track files with a colon (':') in the filename due to a parsing error, allowing resource leaks. I originally encountered this while working with filenames that include ISO8601 timestamps with colons as time separators.

Minimal example:

$ python -c "from multiprocessing.shared_memory import SharedMemory; shm = SharedMemory(create=True, size=1, name='a:b')"
$ Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/resource_tracker.py", line 199, in main
    cmd, name, rtype = line.strip().decode('ascii').split(':')
ValueError: too many values to unpack (expected 3)
$ ls /dev/shm/a\:b
/dev/shm/a:b

Without the colon, the file is correctly tracked and removed:

$ python -c "from multiprocessing.shared_memory import SharedMemory; shm = SharedMemory(create=True, size=1, name='ab')"
$ /usr/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked shared_memory objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
$ ls /dev/shm/ab
ls: cannot access '/dev/shm/ab': No such file or directory

Your environment

  • CPython versions tested on: 3.10.7, 3.11.0, 3.12.0a1
  • Operating system and architecture: Fedora 35 x86_64 (3.10.7 from Fedora, others with Docker images)

Linked PRs

Activity

  1. saito828koki commented on Nov 1, 2022

    @saito828koki
    Contributor

    @maaleske
    Thanks for your report.
    In my opinion, making colons unusable in resource names is a reasonable fix for this issue. (We should also check if other parts of multiprocessing using resource_tracker like multiprocessing.synchronize.SemLock will cause the same problem. )

    Are there better ways to fix this issue?

  2. maaleske commented on Nov 1, 2022

    @maaleske
    Author

    @saito828koki
    That is poor solution, since the issue is still present if the resource is not created by the Python process, but just opened through SharedMemory (as was the case in my original encounter with it). Disallowing colons would make SharedMemory unusable in situations where Python is not in charge of the filenames, which I imagine to be a common use of shared memory resources.

    I also investigated a bit more and colons are not the only problem; if the filenames contain newlines (again, valid on Linux) and colons, you can trigger other errors from the same code path, and I think there may even be a way to induce the resource tracker to unlink the wrong files by injecting an extra \ncmd:name:rtype\n in to the file through the filename, though I didn't yet find a working example.

    Given that Python might not be the one responsible for the filenames, the real fix is to not parse them and store them in a way that does not require it. If you want to be rigorous, I think you would have to store each filename in a separate file, and manage the related cmd/rtype in some way.
    However, there is also an issue related to incorrect behaviour of the resource tracker (#82300), with one fix proposing to remove it altogether for shared memory resources, which would make this a non-issue for SHM, but still probably relevant for semaphores.

  3. added 2 commits that reference this issue on Sep 2, 2025
  4. added a commit that references this issue on Nov 12, 2025
  5. added a commit that references this issue on Nov 24, 2025
  6. added a commit that references this issue on Nov 27, 2025
  7. added a commit that references this issue on Nov 27, 2025
  8. added a commit that references this issue on Nov 28, 2025
  9. added a commit that references this issue on Dec 6, 2025
  10. flucasgabriel58-eng commented on Jan 13, 2026

    @flucasgabriel58-eng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions