Skip to content

Commit

Permalink
Monitor remote nodes in attach mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jul 11, 2024
1 parent 77fcebb commit 87e5c6c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion apps/debug_adapter/lib/debug_adapter/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,28 @@ defmodule ElixirLS.DebugAdapter.Server do
{:noreply, state}
end

def handle_info({:nodeup, node, %{node_type: node_type}}, state = %__MODULE__{}) do
Output.debugger_console("#{node_type} node #{node} connected\n")
{:noreply, state}
end

def handle_info(
{:nodedown, node, %{node_type: node_type, nodedown_reason: nodedown_reason}},
state = %__MODULE__{}
) do
Output.debugger_console(
"#{node_type} node #{node} disconnected: #{inspect(nodedown_reason)}\n"
)

{:noreply, state}
end

# If we get the disconnect request from the client, we continue with :disconnect so the server will
# die right after responding to the request
@impl GenServer
def handle_continue(:disconnect, state = %__MODULE__{}) do
unless :persistent_term.get(:debug_adapter_test_mode, false) do
Output.debugger_console("Received disconnect request")
Output.debugger_console("Received disconnect request\n")
Process.sleep(200)
System.stop(0)
else
Expand Down Expand Up @@ -806,6 +822,12 @@ defmodule ElixirLS.DebugAdapter.Server do
defp handle_request(attach_req(_, config), state = %__MODULE__{}) do
server = self()

:net_kernel.monitor_nodes(true, %{
connection_id: false,
node_type: :all,
nodedown_reason: true
})

{_, ref} = spawn_monitor(fn -> attach(config, server) end)

config =
Expand Down

0 comments on commit 87e5c6c

Please sign in to comment.