Skip to content

Commit

Permalink
Ignore errors when releasing RPC sessions.
Browse files Browse the repository at this point in the history
I'm not sure why / when these happen yet, as I can't reproduce quite
yet, but doing this is "safe" in the sense that on the Lean side all
that will happen is some bit of leaking memory.

Let's choose that over an error for now until we figure out what else we
should be doing (or aren't doing).
  • Loading branch information
Julian committed Oct 26, 2024
1 parent 3c5a4f7 commit 464f6ad
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lua/lean/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local rpc = {}
---@field client vim.lsp.Client
---@field uri string
---@field connected? boolean
---@field session_id? string
---@field session_id? integer
---@field connect_err? string
---@field on_connected Condvar
---@field keepalive_timer? uv_timer_t
Expand Down Expand Up @@ -92,17 +92,39 @@ function Session:close()
self:close_without_releasing()
end

---A notification to release remote references. Should be sent by the client when it no longer needs
---`RpcRef`s it has previously received from the server. Not doing so is safe but will leak memory.
---@class RpcReleaseParams
---@field uri lsp.DocumentUri
---@field sessionId integer
---@field refs RpcRef[]

---@param refs RpcRef[]
function Session:release_now(refs)
vim.list_extend(self.to_release, refs)
if #self.to_release == 0 or self:is_closed() then
return
end
self.client.notify('$/lean/rpc/release', {

log:debug {
message = 'releasing RPC refs',
uri = self.uri,
refs = refs,
}

---@type RpcReleaseParams
local params = {
uri = self.uri,
sessionId = self.session_id,
refs = self.to_release,
})
}
local succeeded = pcall(self.client.notify, '$/lean/rpc/release', params)
if not succeeded then
log:warning {
message = 'unable to release RPC session, which leaks a bit of memory',
params = params,
}
end
self.to_release = {}
end

Expand Down

0 comments on commit 464f6ad

Please sign in to comment.