swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.3k stars 273 forks source link

IndexStoreDB leaks threads on Linux #1456

Open ahoppen opened 3 months ago

ahoppen commented 3 months ago

Issue found by thread sanitizer:

  Thread T31 (tid=31250, finished) created by thread T7 at:
    #0 pthread_create ??:? (SourceKitLSPPackageTests.xctest+0x3da5c0)
    #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) ??:? (libstdc++.so.6+0xd3320) (BuildId: a012b2bb77110e84b266cd7425b50e57427abb02)
    #2 (anonymous namespace)::IndexDatastoreImpl::init(std::shared_ptr<indexstore::IndexStore>, std::shared_ptr<IndexStoreDB::index::SymbolIndex>, std::shared_ptr<IndexStoreDB::index::IndexSystemDelegate>, std::shared_ptr<IndexStoreDB::CanonicalPathCache>, IndexStoreDB::index::CreationOptions const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) IndexDatastore.cpp:? (SourceKitLSPPackageTests.xctest+0xcfb7a8)
    #3 IndexStoreDB::index::IndexDatastore::create(std::shared_ptr<indexstore::IndexStore>, std::shared_ptr<IndexStoreDB::index::SymbolIndex>, std::shared_ptr<IndexStoreDB::index::IndexSystemDelegate>, std::shared_ptr<IndexStoreDB::CanonicalPathCache>, IndexStoreDB::index::CreationOptions const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ??:? (SourceKitLSPPackageTests.xctest+0xcfb330)
    #4 (anonymous namespace)::IndexSystemImpl::init(indexstoredb_llvm::StringRef, indexstoredb_llvm::StringRef, std::shared_ptr<IndexStoreDB::index::IndexStoreLibraryProvider>, std::shared_ptr<IndexStoreDB::index::IndexSystemDelegate>, IndexStoreDB::index::CreationOptions const&, indexstoredb_llvm::Optional<unsigned long>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) IndexSystem.cpp:? (SourceKitLSPPackageTests.xctest+0xd38a48)
    #5 IndexStoreDB::index::IndexSystem::create(indexstoredb_llvm::StringRef, indexstoredb_llvm::StringRef, std::shared_ptr<IndexStoreDB::index::IndexStoreLibraryProvider>, std::shared_ptr<IndexStoreDB::index::IndexSystemDelegate>, IndexStoreDB::index::CreationOptions const&, indexstoredb_llvm::Optional<unsigned long>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ??:? (SourceKitLSPPackageTests.xctest+0xd381e4)
    #6 indexstoredb_index_create ??:? (SourceKitLSPPackageTests.xctest+0xc76bbc)
    #7 $s12IndexStoreDBAAC9storePath08databaseE07library8delegate22useExplicitOutputUnits25waitUntilDoneInitializing8readonly27enableOutOfDateFileWatching18listenToUnitEvents14prefixMappingsABSS_SSAA0aB7LibraryCSgAA0A8Delegate_pSgS5bSayAA0E7MappingVGtKcfc ??:? (SourceKitLSPPackageTests.xctest+0xc5d6fc)
    #8 $s12IndexStoreDBAAC9storePath08databaseE07library8delegate22useExplicitOutputUnits25waitUntilDoneInitializing8readonly27enableOutOfDateFileWatching18listenToUnitEvents14prefixMappingsABSS_SSAA0aB7LibraryCSgAA0A8Delegate_pSgS5bSayAA0E7MappingVGtKcfC ??:? (SourceKitLSPPackageTests.xctest+0xc5d028)
    #9 $s12SourceKitLSP9WorkspaceC15documentManager7rootUri18capabilityRegistry11buildSystem09toolchainJ07options12indexOptions0O13TaskScheduler20logMessageToIndexLog0O18TasksWereScheduled0O23ProgressStatusDidChangeAcA08DocumentF0C_22LanguageServerProtocol11DocumentURIVAA010CapabilityJ0C6SKCore05BuildL0_pSgAV09ToolchainJ0CAA0aB9LSPServerC0P0VAA0vP0VAV0qR0Cy08SemanticV003AnyvQ11DescriptionVGyAV0vQ2IDO_SStYbcySiYbcyyYbctYaKcfCTY8_ Workspace.swift.o:? (SourceKitLSPPackageTests.xctest+0x24d3568)
    #10 swift::runJobInEstablishedExecutorContext(swift::Job*) crtstuff.c:? (libswift_Concurrency.so+0x61124)
    #11 _dispatch_continuation_pop :? (libdispatch.so+0x2a720)

To reproduce, run the following in eg. a nightly jammy container

swift test -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block --sanitize=thread --filter testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled

The issue does not reproduce on macOS.

rdar://129435830