Skip to content

runtime: destroy the M's semaphore when it exits on AIX - #82521

Open
thevilledev wants to merge 1 commit into
golang:masterfrom
thevilledev:fix/aix-mdestroy-sem
Open

thevilledev wants to merge 1 commit into
golang:masterfrom
thevilledev:fix/aix-mdestroy-sem

Conversation

@thevilledev

Copy link
Copy Markdown
Contributor

semacreate allocates an unnamed POSIX semaphore on the C heap and
initializes it with sem_init, but mdestroy never released it. On AIX
sem_init fails with ENOSPC once SEM_NSEMS_MAX semaphores exist (32768
on AIX 7.3), so a program that keeps retiring Ms (for example a
goroutine that parks once and then returns while locked to its thread)
fails in semacreate with "fatal error: sem_init" after about 32000
retired threads. The malloc'd storage leaked as well.

Call sem_destroy and free from mdestroy, which runs after the exiting M
stops taking locks.

Add an AIX test that retires 40000 locked Ms that have each parked
once. It is in testprogcgo because without cgo, exited threads do not
exit on AIX until CL 849968 lands. Without the fix, the test fails with
"fatal error: sem_init".

Fixes #82305

semacreate allocates an unnamed POSIX semaphore on the C heap and
initializes it with sem_init, but mdestroy never released it. On AIX
sem_init fails with ENOSPC once SEM_NSEMS_MAX semaphores exist (32768
on AIX 7.3), so a program that keeps retiring Ms (for example a
goroutine that parks once and then returns while locked to its thread)
fails in semacreate with "fatal error: sem_init" after about 32000
retired threads. The malloc'd storage leaked as well.

Call sem_destroy and free from mdestroy, which runs after the exiting M
stops taking locks.

Add an AIX test that retires 40000 locked Ms that have each parked
once. It is in testprogcgo because without cgo, exited threads do not
exit on AIX until CL 849968 lands. Without the fix, the test fails with
"fatal error: sem_init".

Fixes golang#82305
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 262c7da) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/853945.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

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.

runtime: each exited thread leaks a semaphore on AIX

2 participants