Skip to content

Bug: Lack of exception trace#732

Merged
hhubert6 merged 4 commits intomainfrom
717-tracing-exceptions-in-handle_info
Sep 9, 2025
Merged

Bug: Lack of exception trace#732
hhubert6 merged 4 commits intomainfrom
717-tracing-exceptions-in-handle_info

Conversation

@hhubert6
Copy link
Contributor

@hhubert6 hhubert6 commented Sep 5, 2025

This behavior happen due to reading state of dead live view (while saving it)

:ok <- StateActions.maybe_save_state!(updated_trace),

which stops trace handling, raises error and crashes gen_server. When gen_server is started again all other traces that were stored in a gen_server inbox are lost and thus I assume the handle_info which ended with exception with them.

def handle_cast({:new_trace, {_, pid, type, {module, fun, _}, _, return_ts}, _n}, state)
    when fun in @allowed_callbacks and type in [:return_from, :exception_from] do
  with trace_key <- {pid, module, fun},
       {ref, trace, ts} <- get_trace_record(state, trace_key),
       execution_time <- calculate_execution_time(return_ts, ts),
       params <- %{execution_time: execution_time, type: type},
       {:ok, updated_trace} <- TraceActions.update_trace(trace, params),
       {:ok, ref} <- TraceActions.persist_trace(updated_trace, ref),
       :ok <- StateActions.maybe_save_state!(updated_trace),
       :ok <- TraceActions.publish_trace(updated_trace, ref) do
    {:noreply, delete_trace_record(state, trace_key)}
  else
    :trace_record_not_found ->
      {:noreply, state}

    {:error, err} ->
      raise "Error while handling trace: #{inspect(err)}"
  end
end

Simplest solution is to keep tracing flow despite of the result of saving state

_ <- StateActions.maybe_save_state!(updated_trace),

@hhubert6 hhubert6 linked an issue Sep 5, 2025 that may be closed by this pull request
@hhubert6 hhubert6 marked this pull request as ready for review September 5, 2025 15:23
Copy link
Member

@kraleppa kraleppa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good - is possible to test if exception trace does appear?

@hhubert6
Copy link
Contributor Author

hhubert6 commented Sep 9, 2025

Looking good - is possible to test if exception trace does appear?

I've added a usual scenario of clicking crash button in LiveDebuggerDev.LiveViews.Main. Recreating the situation in which this exact bug occurred is very tedious so I didn't try to make it in test. Or do you insist to do it?

cc @kraleppa

@hhubert6 hhubert6 requested a review from kraleppa September 9, 2025 09:42
@kraleppa
Copy link
Member

kraleppa commented Sep 9, 2025

@hhubert6 I think it's fine

Looking good - is possible to test if exception trace does appear?

I've added a usual scenario of clicking crash button in LiveDebuggerDev.LiveViews.Main. Recreating the situation in which this exact bug occurred is very tedious so I didn't try to make it in test. Or do you insist to do it?

cc @kraleppa

I think it's good enough 👍

@hhubert6 hhubert6 merged commit 4e8fc05 into main Sep 9, 2025
2 checks passed
@hhubert6 hhubert6 deleted the 717-tracing-exceptions-in-handle_info branch September 9, 2025 10:05
hhubert6 added a commit that referenced this pull request Sep 9, 2025
* Fix

* Fix ProcessMonitor crashing when live view not alive

* Add test for exception trace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracing exceptions in handle_info

3 participants