Skip to content

Commit 5527dd1

Browse files
committed
Rescue IOError during shutdown
1 parent 83cd510 commit 5527dd1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ def initialize
8484
if @wait_thread.alive?
8585
$stderr.puts("Ruby LSP Rails is force killing the server")
8686
sleep(0.5) # give the server a bit of time if we already issued a shutdown notification
87-
88-
# Windows does not support the `TERM` signal, so we're forced to use `KILL` here
89-
Process.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
87+
force_kill
9088
end
9189
end
9290
end
@@ -149,6 +147,9 @@ def shutdown
149147
send_message("shutdown")
150148
sleep(0.5) # give the server a bit of time to shutdown
151149
[@stdin, @stdout, @stderr].each(&:close)
150+
rescue IOError
151+
# The server connection may have died
152+
force_kill
152153
end
153154

154155
sig { returns(T::Boolean) }
@@ -229,6 +230,11 @@ def rails_root
229230

230231
private
231232

233+
def force_kill
234+
# Windows does not support the `TERM` signal, so we're forced to use `KILL` here
235+
Process.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
236+
end
237+
232238
sig { override.params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
233239
def send_message(request, params = nil)
234240
# no-op

0 commit comments

Comments
 (0)