Workaround SR-13822 by keeping the file handle alive for the connection

On Linux, the file handle is closing the file descriptor on deinit
despite `closeOnDealloc: false`
(https://bugs.swift.org/browse/SR-13822). Workaround by keping the
FileHandle alive.

rdar://70995458
This commit is contained in:
Ben Langmuir
2020-11-03 10:15:16 -08:00
parent 0068eae68f
commit 26f134ff2e

View File

@@ -159,10 +159,12 @@ struct Main: ParsableCommand {
fatalError("failed to redirect stdout -> stderr: \(strerror(errno)!)")
}
let realStdoutHandle = FileHandle(fileDescriptor: realStdout, closeOnDealloc: false)
let clientConnection = JSONRPCConnection(
protocol: MessageRegistry.lspProtocol,
inFD: FileHandle.standardInput,
outFD: FileHandle(fileDescriptor: realStdout, closeOnDealloc: false),
outFD: realStdoutHandle,
syncRequests: syncRequests
)
@@ -174,6 +176,9 @@ struct Main: ParsableCommand {
})
clientConnection.start(receiveHandler: server, closeHandler: {
server.prepareForExit()
// FIXME: keep the FileHandle alive until we close the connection to
// workaround SR-13822.
withExtendedLifetime(realStdoutHandle) {}
// Use _Exit to avoid running static destructors due to SR-12668.
_Exit(0)
})