Skip to content

Fix logger crash when :gen_statem format_status/2 returns non-tuple #13684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2024

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Jun 22, 2024

Closes #13682

Will backport after merge.

@sabiwara sabiwara marked this pull request as draft June 22, 2024 00:25
@sabiwara sabiwara force-pushed the fix_gen_statem_logger_crash branch from 902068e to a7c7aeb Compare June 22, 2024 01:11
@sabiwara sabiwara changed the title Fix logger crash for :gen_statem :handle_event_function callback mode Fix logger crash when :gen_statem format_status/3 returns non-tuple Jun 22, 2024
@sabiwara sabiwara marked this pull request as ready for review June 22, 2024 01:13
@sabiwara sabiwara force-pushed the fix_gen_statem_logger_crash branch 2 times, most recently from 5ac3e7b to 9efe6b8 Compare June 22, 2024 01:23
@sabiwara sabiwara changed the title Fix logger crash when :gen_statem format_status/3 returns non-tuple Fix logger crash when :gen_statem format_status/2 returns non-tuple Jun 22, 2024
@@ -324,12 +324,19 @@ defmodule Logger.Translator do
["\nPostponed: #{inspect(postponed, inspect_opts)}"]

if min_level == :debug do
state_info =
case state do
{state, data} ->
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be a user defined tuple then? That we think is State+Data, but it is just something else? How does Erlang/OTP report those? Is there another key we could look at instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I should really always ask myself "what would Erlang do?" 😄

Indeed, it seems there is no such thing as State-Data unpacking, just State: https://github.com/erlang/otp/blob/OTP-27.0/lib/stdlib/src/gen_statem.erl#L4554-L4616. Will fix accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dadb797

@sabiwara sabiwara force-pushed the fix_gen_statem_logger_crash branch from 9efe6b8 to dadb797 Compare June 22, 2024 08:21
@@ -552,6 +570,34 @@ defmodule Logger.TranslatorTest do
assert_receive {:event, {:string, ["Process " | _]}, _process_metadata}
end

test "translates :gen_statem crashes when format_status/2 does not return a tuple" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we keep this test just in case to prevent similar regressions?
It feels like a bit artificial now that there is no code assuming a tuple in the first place.
No strong opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I would nuke it, yeah. :)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, to be clear, we should have tests for both styles of gen_statem, but perhaps we should change its name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, like 578e043?

Queue: .*
Postponed: \[\]
State: :ok
Callback mode: .*, state_enter: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I can't check for callback mode because of erlang/otp#8605

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

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

Ship it! Also please backport it!

@sabiwara sabiwara merged commit 2eb85ea into elixir-lang:main Jun 22, 2024
9 checks passed
@sabiwara sabiwara deleted the fix_gen_statem_logger_crash branch June 22, 2024 11:14
@sabiwara
Copy link
Contributor Author

Backported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Failure while translating Erlang's logger event (gen_statem)
2 participants