Skip to content

Improve logging: reduce verbosity for general messages and prevent cr…#3

Merged
sylane merged 2 commits intomainfrom
sylane/better-logging
Mar 10, 2025
Merged

Improve logging: reduce verbosity for general messages and prevent cr…#3
sylane merged 2 commits intomainfrom
sylane/better-logging

Conversation

@sylane
Copy link
Contributor

@sylane sylane commented Mar 10, 2025

…ash logs

  • Lower generla log level
  • Use shutdown error reasons to prevent crash logs
  • Better gun error handling
  • Better connection cleanup

…ash logs

 - Lower generla log level
 - Use shutdown error reasons to prevent crash logs
 - Better gun error handling
 - Better connection cleanup
@sylane sylane force-pushed the sylane/better-logging branch from a53bdae to c5cf234 Compare March 10, 2025 08:20
Comment on lines 389 to 400
handle_common(info, {'DOWN', _, process, Pid, Reason}, StateName,
Data = #data{gun_pid = Pid}) ->
?JARL_INFO("gun process of the connection to ~s crashed: ~p",
[Data#data.uri, Reason],
#{event => ws_gun_crash, uri => Data#data.uri,
reason => Reason, state => StateName}),
{stop, Reason, connection_closed(Data, closed)};
?JARL_DEBUG("Gun process for the connection to ~s terminated: ~w",
[Data#data.uri, Reason],
#{event => ws_exit, uri => Data#data.uri,
reason => Reason, state => StateName}),
SafeReason = case Reason of
normal -> normal;
{shutdown, R} -> {shutdown, R};
R -> {shutdown, R}
end,
{stop, SafeReason, Data};
Copy link
Member

Choose a reason for hiding this comment

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

With the code in terminate/3 and connection_close/2 I have the impression that we will try to stop gun a second time. In connection_close/2, gun:shutdown(GunPid) is called but if we receive the DOWN message that means that gun is already down.
Could this trigger a crash ?

Copy link
Member

Choose a reason for hiding this comment

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

From the docs it looks like gun:shutdown tells gun to gracefully stop and prevents itself from re-attempting to connect.

Copy link
Contributor Author

@sylane sylane Mar 10, 2025

Choose a reason for hiding this comment

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

With the code in terminate/3 and connection_close/2 I have the impression that we will try to stop gun a second time. In connection_close/2, gun:shutdown(GunPid) is called but if we receive the DOWN message that means that gun is already down. Could this trigger a crash ?

@GwendalLaurent This is why I am not calling connection_close anymore when stopping. I am not sure I am understanding your concerns...

Copy link
Member

Choose a reason for hiding this comment

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

I think the concearn is about calling gun:shutdown(GunPid) when you already received a DOWN from such Pid.
MAybe you could set the Pid to #data{gun_pid = undefined} to avoid calling gun:shutdown later

Copy link
Member

@ziopio ziopio Mar 10, 2025

Choose a reason for hiding this comment

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

you are calling connection_close in terminate

Copy link
Member

Choose a reason for hiding this comment

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

Yes exactly, you receive a DOWN message indicating that gun is already down but then still call gun:shutdown(GunPid) during the terminate flow (in connection_close/2) . My concern is that the GunPid won't exist anymore and trigger a crash

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, I got it, nice catch. I don't think this is crashing, otherwise the tests would have failed, but I'll put back the call to connection_closed/2.

@sylane sylane merged commit 74f72a7 into main Mar 10, 2025
@sylane sylane deleted the sylane/better-logging branch March 10, 2025 14:44
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.

3 participants