Skip to content

Commit

Permalink
Merge pull request #10 from thalesmg/fix-log-spam
Browse files Browse the repository at this point in the history
fix: reduce log spamming when connection goes down
  • Loading branch information
thalesmg authored May 10, 2024
2 parents 563c801 + b40402b commit 343d96a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/epgsql.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, epgsql,
[{description, "PostgreSQL Client"},
{vsn, "4.7.1.1"},
{vsn, "4.7.1.2"},
{modules, []},
{registered, []},
{applications, [kernel,
Expand Down
11 changes: 9 additions & 2 deletions src/epgsql_sock.erl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ handle_info({Passive, Sock}, #state{sock = Sock} = State)

handle_info({Closed, Sock}, #state{sock = Sock} = State)
when Closed == tcp_closed; Closed == ssl_closed ->
{stop, sock_closed, flush_queue(State#state{sock = undefined}, {error, sock_closed})};
{stop, {shutdown, sock_closed}, flush_queue(State#state{sock = undefined}, {error, sock_closed})};

handle_info({Error, Sock, Reason}, #state{sock = Sock} = State)
when Error == tcp_error; Error == ssl_error ->
Expand Down Expand Up @@ -408,8 +408,9 @@ command_exec(Transport, Command, CmdState, State) ->
_ ->
{noreply, finish(State2, Result)}
end;
{stop, StopReason, Response, State1} ->
{stop, StopReason0, Response, State1} ->
reply(Transport, Response, Response),
StopReason = maybe_silence_reason(StopReason0),
{stop, StopReason, State1}
end.

Expand Down Expand Up @@ -831,6 +832,12 @@ handle_xlog_data(StartLSN, EndLSN, WALRecord,
redact_state(State) ->
State#state{rows = information_redacted}.

%% Avoid spamming logs with crash reports for potentially transient failures.
maybe_silence_reason(econnrefused = Reason) ->
{shutdown, Reason};
maybe_silence_reason(Reason) ->
Reason.

-ifdef(TEST).

state_to_map(State) ->
Expand Down
2 changes: 1 addition & 1 deletion test/epgsql_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ connect_to_closed_port(Config) ->
"epgsql_test",
"epgsql_test",
[{port, Port + 1}, {database, "epgsql_test_db1"}])),
?assertMatch({'EXIT', _, econnrefused}, receive Stop -> Stop end),
?assertMatch({'EXIT', _, {shutdown, econnrefused}}, receive Stop -> Stop end),
process_flag(trap_exit, Trap).

prepared_query(Config) ->
Expand Down

0 comments on commit 343d96a

Please sign in to comment.