@owenv could you share a way to repro those hangs?
FWIW we should probably converge onto a single approach there and here. JSONRPCConnection is a pretty thin wrapper around the subprocess, so if swift-subprocess is the plan there then maybe we should also be doing it here, unless I’m missing something (hopefully it’s not DispatchIO based as then we’re back to the original problem..). All the wrapper needs is post data to stdin, realtime handler of stdout and a way to properly handling close()
And btw I did end up running into issues with close() during local testing as there is a specific test testCloseRace here which catches an issue that I’m yet to investigate
connection.serverToClientConnection.close()
try await fulfillmentOfOrThrow(expectation)
}
/// We can explicitly close a connection, but the connection also
/// automatically closes itself if the pipe is closed (or has an error).
/// DispatchIO can make its callback at any time, so this test is to try to
/// provoke a race between those things and ensure the closeHandler is called
/// exactly once.
func testCloseRace() async throws {
for _ in 0...100 {
let to = Pipe()
let from = Pipe()
let expectation = self.expectation(description: "closed")
expectation.assertForOverFulfill = true
let conn = JSONRPCConnection(
name: "test",
protocol: MessageRegistry(requests: [], notifications: []),
inFD: to.fileHandleForReading,
My issue with close() turned out to be a user error (missing ioGroup.leave())
I uploaded the last version of the code to Prototype pipe handling without dispatch IO by roman-bcny · Pull Request #2315 · swiftlang/sourcekit-lsp · GitHub and sent that for review. It’s using availableData and I’m not seeing issues with parallel tests locally. If someone can provide a repro of availableData misbehaving I can try to dig into that as well.
PS. Github didn’t notify me about those comments some of you left on my draft PR so I only saw them today after uploading my latest changes!
1 Like
Sorry to revive an old thread... Have attempts to fix this long-standing bug really failed?
ahoppen
(Alex Hoppen)
March 26, 2026, 7:49am
24
This should be fixed in SourceKit-LSP shipping with Swift 6.3.
This was what I expected. But the high CPU usage is still there. It looks like the fix (if there is one) was not included in the 6.3 release.
Also, why the GitHub - swiftlang/sourcekit-lsp: Language Server Protocol implementation for Swift and C-based languages · GitHub shows the latest release as Swift 6.1.1 dated May 24, 2025 ?
ahoppen
(Alex Hoppen)
March 26, 2026, 3:22pm
26
I just double-checked and it seems like Address review comments on `JSONRPCConnection` update by bnbarham · Pull Request #29 · swiftlang/swift-tools-protocols · GitHub indeed did not make it into the 6.3 release. It only exists in swift-tools-protocols 0.10.0 but 6.3 still references 0.9.0 (swift/utils/update_checkout/update-checkout-config.json at release/6.3 · swiftlang/swift · GitHub ).
It should be fixed in the nightly main toolchains though. Sorry for causing the confusion.
2 Likes