Skip to content

Commit d78d6fb

Browse files
committed
Fix deadlock in exit -> onExit -> close -> closeHandler -> sync
1 parent ac630e4 commit d78d6fb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/SourceKit/SourceKitServer.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class SourceKitServer: LanguageServer {
4646

4747
let fs: FileSystem
4848

49-
let onExit: () -> Void
49+
var onExit: () -> Void
5050

5151
/// Creates a language server for the given client.
5252
public init(client: Connection, fileSystem: FileSystem = localFileSystem, options: Options, onExit: @escaping () -> Void = {}) {
@@ -385,7 +385,13 @@ extension SourceKitServer {
385385
func exit(_ notification: Notification<Exit>) {
386386
// Should have been called in shutdown, but allow misbehaving clients.
387387
_prepareForExit()
388-
onExit()
388+
389+
// Call onExit only once, and hop off queue to allow the handler to call us back.
390+
let onExit = self.onExit
391+
self.onExit = {}
392+
DispatchQueue.global().async {
393+
onExit()
394+
}
389395
}
390396

391397
// MARK: - Text synchronization

0 commit comments

Comments
 (0)