Skip to content

runtime_tools: fix dbg:session/2 cleanup when calling process exits#11260

Open
madlep wants to merge 3 commits into
erlang:maintfrom
madlep:runtime_tools/dbg-session-handle-parent-exit
Open

runtime_tools: fix dbg:session/2 cleanup when calling process exits#11260
madlep wants to merge 3 commits into
erlang:maintfrom
madlep:runtime_tools/dbg-session-handle-parent-exit

Conversation

@madlep

@madlep madlep commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

If process that called dbg:session/2 exits before dbg:session_destroy/1 is called, an error is encountered and an error report logged, and any trace messages are lost and not delivered.

The existing logic seemed to be treating the Session stored in the process dictionary as a dbg:session() type (ie a pid), and passing it to dbg:session_destroy/1, however, it is actually a trace session, and can't be used directly as a pid in dbg:session_destroy/1

Instead, fix this by extracting logic from stop message handler clause to clean up and ensure messages are delivered in the same way.

This issue can be reproduced with the following code:

1> spawn_link(fun() ->
     DbgSession = dbg:session_create(my_session),
     dbg:session(DbgSession, fun() ->
       dbg:tracer()
     end)
   end).
<0.102.0>
=ERROR REPORT==== 17-Jun-2026::22:04:51.331934 ===
Error in process <0.103.0> with exit value:
{badarg,[{erlang,monitor,
                 [process,{#Ref<0.3577390006.3558211590.1705>,{my_session,0}}],
                 [{error_info,#{module => erl_erts_errors}}]},
         {dbg,session_destroy,1,[{file,"dbg.erl"},{line,1741}]},
         {dbg,loop,4,[{file,"dbg.erl"},{line,1948}]}]}
  • Added test that fails with old code, and works with fix
  • Fixed compiler warnings due to deprecated catch usage in test module
  • Fixed test failure due to long atom names being passed to list_to_atom/1 due to long release path name on local laptop.

madlep added 3 commits June 17, 2026 21:48
If process that called `dbg:session/2` exits before
`dbg:session_destroy/1 is called, an error is encountered and an error
report logged, and any trace messages are lost and not delivered.

The existing logic seemed to be treating the `Session` stored in the
process dictionary as a `dbg:session()` type (ie a pid), and passing it
to `dbg:session_destroy/1`, however, it is actually a `trace` session,
and can't be used directly as a pid in `dbg:session_destroy/1`

Instead, fix this by extracting logic from `stop` message handler clause
to clean up and ensure messages are delivered in the same way.

This issue can be reproduced with the following code:

```erlang
1> spawn_link(fun() ->
     DbgSession = dbg:session_create(my_session),
     dbg:session(DbgSession, fun() ->
       dbg:tracer()
     end)
   end).
<0.102.0>
=ERROR REPORT==== 17-Jun-2026::22:04:51.331934 ===
Error in process <0.103.0> with exit value:
{badarg,[{erlang,monitor,
                 [process,{#Ref<0.3577390006.3558211590.1705>,{my_session,0}}],
                 [{error_info,#{module => erl_erts_errors}}]},
         {dbg,session_destroy,1,[{file,"dbg.erl"},{line,1741}]},
         {dbg,loop,4,[{file,"dbg.erl"},{line,1948}]}]}
```
If the generated release directory name is very long, it can exceed the
255 character atom name limit, and result in test failures to due
exceeding system limits. Truncate the atom name to 255 chars - which
matches what the code under test does anyway.
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

  2 files   20 suites   4m 17s ⏱️
153 tests 135 ✅ 18 💤 0 ❌
171 runs  153 ✅ 18 💤 0 ❌

Results for commit 40cebba.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Jun 22, 2026
@bjorng bjorng requested a review from sverker June 22, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants