Skip to content

Commit 40dfb8c

Browse files
authored
Merge pull request #343 from benlangmuir/workaround-SR-13822
Workaround SR-13822 by keeping the file handle alive for the connection
2 parents 0068eae + 26f134f commit 40dfb8c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/sourcekit-lsp/main.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ struct Main: ParsableCommand {
159159
fatalError("failed to redirect stdout -> stderr: \(strerror(errno)!)")
160160
}
161161

162+
let realStdoutHandle = FileHandle(fileDescriptor: realStdout, closeOnDealloc: false)
163+
162164
let clientConnection = JSONRPCConnection(
163165
protocol: MessageRegistry.lspProtocol,
164166
inFD: FileHandle.standardInput,
165-
outFD: FileHandle(fileDescriptor: realStdout, closeOnDealloc: false),
167+
outFD: realStdoutHandle,
166168
syncRequests: syncRequests
167169
)
168170

@@ -174,6 +176,9 @@ struct Main: ParsableCommand {
174176
})
175177
clientConnection.start(receiveHandler: server, closeHandler: {
176178
server.prepareForExit()
179+
// FIXME: keep the FileHandle alive until we close the connection to
180+
// workaround SR-13822.
181+
withExtendedLifetime(realStdoutHandle) {}
177182
// Use _Exit to avoid running static destructors due to SR-12668.
178183
_Exit(0)
179184
})

0 commit comments

Comments
 (0)