Skip to content

Commit

Permalink
Remove elements from outstandingRequests on crash
Browse files Browse the repository at this point in the history
Otherwise, we can have a retain cycle where the `OutstandingRequest` keeps the `JSONRPCConnection` alive.

Also move the code that handled `outstandingRequests` out of the `Task` because `outstandingRequests` should only be accessed from `queue`.
  • Loading branch information
ahoppen committed Oct 5, 2024
1 parent 62271b4 commit e50b4d7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Sources/LanguageServerProtocolJSONRPC/JSONRPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ public final class JSONRPCConnection: Connection {
)

ioGroup.notify(queue: queue) { [weak self] in
guard let self = self else { return }
guard let self else { return }
for outstandingRequest in self.outstandingRequests.values {
outstandingRequest.replyHandler(LSPResult.failure(ResponseError.internalError("JSON-RPC Connection closed")))
}
self.outstandingRequests = [:]
self.receiveHandler = nil // break retain cycle
Task {
for outstandingRequest in self.outstandingRequests.values {
outstandingRequest.replyHandler(LSPResult.failure(ResponseError.internalError("JSON-RPC Connection closed")))
}
await self.closeHandler?()
self.receiveHandler = nil // break retain cycle
}
}

Expand Down

0 comments on commit e50b4d7

Please sign in to comment.