Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock when using fork whilst multiprocessing.resource_tracker._resource_tracker._lock is held #96971

Open
TheMinefighter opened this issue Sep 20, 2022 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@TheMinefighter
Copy link

TheMinefighter commented Sep 20, 2022

Bug report

Given the following situation: You have a Process "a" with two threads ("aa", "ab"). aa is currently creating a shared memory segment and is holding multiprocessing.resource_tracker._resource_tracker._lock for that reason. Note that that lock is not acquired by user code, but deep inside the SharedMemory constructor.

ab now wants to create a second process using the fork method. Process b is created with one thread: bb. As per man fork the thread aa is not duplicated in process b.

If aa now finishes creating its SharedMemory it releases multiprocessing.resource_tracker._resource_tracker._lock. But that lock is only a threading.Lock, which means it is released only in process a. In process b it will not be released. If b now wants to create a SharedMemory object and therefore tries to acquire multiprocessing.resource_tracker._resource_tracker._lock this will take forever, as it will never be free in process b. man fork explicitly mentions that such situations are a potential source of issues.

As this is a race condition there is no minimal, reproducible example I can give.

Possible solutions

One could replace this threading.Lock with a multiprocessing.Lock. Alternatively one could replace that lock with a new one in the child process after a fork. Im not sure about the intended behavior of the resource tracker in such situations.

Your environment

  • CPython versions tested on: 3.9, 3.10
  • Operating system and architecture: Unix (Arch, Kernel 5.19.7-1)
@TheMinefighter TheMinefighter added the type-bug An unexpected behavior, bug, or error label Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant