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

[SR-9241] couldn't create pthread key for stdlib TLS: Resource temporarily unavailable #3593

Closed
benlangmuir opened this issue Nov 14, 2018 · 3 comments

Comments

@benlangmuir
Copy link
Member

Previous ID SR-9241
Radar None
Original Reporter @benlangmuir
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Ubuntu 16.04, 18.04

I have seen this in Docker, a VM and physical machine. At one point it wasn't reproducing in docker, but now it seems to. Not sure what configuration difference there may be.

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 261f81f07add698ef88fb90c3b278a2c

Issue Description:

When running SourceKit-LSP's tests on Ubuntu 16.04, I get a strange error:

Test Suite 'CodingTests' started at 2018-11-13 23:58:32.174
Test Case 'CodingTests.testValueCoding' started at 2018-11-13 23:58:32.174
couldn't create pthread key for stdlib TLS: Resource temporarily unavailable
 Aborted (core dumped)

I can reproduce the issue by running all the tests together like this:

$ .build/debug/SourceKitLSPPackageTests.xctest

But if I run each test separately they all pass:

$ for t in `.build/debug/SourceKitLSPPackageTests.xctest --list-tests`; do echo $t && .build/debug/SourceKitLSPPackageTests.xctest $t ; done
@benlangmuir
Copy link
Member Author

Attached a backtrace; nothing jumps out at me. There are 34 threads , but all others are idle.

@benlangmuir
Copy link
Member Author

It looks like we're calling `pthread_key_create` more than `PTHREAD_KEYS_MAX=1024` times. Of that, CoreFoundation makes 1033 calls that look like this:

_CFGetTSDCreateIfNeeded
  __CFTSDInitialize
    pthread_key_create

I found this in lldb:

(lldb) breakpoint list
Current breakpoints:
1: name = 'pthread_key_create', locations = 1, resolved = 1, hit count = 1035 Options: enabled auto-continue 
  1.1: where = libpthread.so.0`__GI___pthread_key_create, address = 0x00007ffff6b31f90, resolved, hit count = 1035 

3: address = libFoundation.so[0x000000000084dc82], locations = 1, resolved = 1, hit count = 1031 Options: enabled auto-continue 
  3.1: where = libFoundation.so`_CFGetTSDCreateIfNeeded + 82, address = 0x00007ffff7a9dc82, resolved, hit count = 1031

(lldb) disas -a 0x00007ffff7a9dc82
<snip>
    0x7ffff7a9dc74 <+68>:  leaq   0x333bfd(%rip), %rdi      ; __CFTSDIndexKey
    0x7ffff7a9dc7b <+75>:  leaq   -0x112(%rip), %rsi        ; __CFTSDFinalize
    0x7ffff7a9dc82 <+82>:  callq  0x7ffff74b4060            ; symbol stub for: pthread_key_create

@benlangmuir
Copy link
Member Author

#1790

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant