Skip to content

Conversation

@dead10ck
Copy link
Contributor

shmget deadlocks when called more than once in the same process. It locks the mutex, then calls ashv_read_remote_segment, which asks the background thread in the same process to find a shmid, which in turn tries to lock the mutex which is already locked. I included a simple trivial test case that hits the deadlock.

I actually found this in Postgres, noticing that a CREATE TABLE AS ... query was never returning, and the process that was executing the query was stuck doing nothing. strace showed one thread stuck reading from a socket, and another stuck waiting on a lock.

`shmget` deadlocks when called more than once in the same process. It
locks the mutex, then calls `ashv_read_remote_segment`, which asks the
background thread in the same process to find a shmid, which in turn
tries to lock the mutex which is already locked.
@ravener ravener dismissed their stale review March 26, 2021 13:31

Nevermind, misunderstood the logic

@Grimler91
Copy link
Member

Nicely done debugging this!

It should not be necessary to bump all packages depending on libandroid-shmem after this, right? (or did you have to rebuild postgres to link it against the new library?)

@dead10ck
Copy link
Contributor Author

Thanks! It was actually kind of fun.

As for patching, I guess it depends on each package, and whether it links statically or dynamically. If dynamically (which I imagine is most), it should not be necessary to do anything to those packages; I did not need to rebuild Postgres, for example. But it might be a good idea to track down if any packages link statically, or do something else (a quick grep shows libcairo looks like it vendors a copy, for example, which probably does require a patch to get this fix applied).

@Grimler91 Grimler91 merged commit 729bb8c into termux:master Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants