Skip to content

Commit 135575b

Browse files
committed
Stream reader: close osiris logs and sockets in terminate
Instead of injecting it into varios places inside the code. When the osiris log is closed it will decrement the global "readers" counter which is why it is much safer to do this in terminate.
1 parent 239e136 commit 135575b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

deps/rabbitmq_stream/src/rabbit_stream_reader.erl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,15 @@
173173
callback_mode() ->
174174
[state_functions, state_enter].
175175

176-
terminate(Reason, State, StatemData) ->
176+
terminate(Reason, State,
177+
#statem_data{transport = Transport,
178+
connection = #stream_connection{socket = Socket},
179+
connection_state = ConnectionState} = StatemData) ->
180+
close(Transport, Socket, ConnectionState),
177181
rabbit_networking:unregister_non_amqp_connection(self()),
178182
notify_connection_closed(StatemData),
179-
rabbit_log:debug("~p terminating in state '~s' with reason '~p'",
180-
[?MODULE, State, Reason]).
183+
rabbit_log:debug("~s terminating in state '~s' with reason '~W'",
184+
[?MODULE, State, Reason, 10]).
181185

182186
start_link(KeepaliveSup, Transport, Ref, Opts) ->
183187
{ok,
@@ -713,7 +717,6 @@ open(info, {OK, S, Data},
713717
#stream_connection{connection_step = Step} = Connection1,
714718
case Step of
715719
closing ->
716-
close(Transport, S, State),
717720
stop;
718721
close_sent ->
719722
rabbit_log_connection:debug("Transitioned to close_sent"),
@@ -808,7 +811,6 @@ open(info, heartbeat_send,
808811
rabbit_log_connection:info("Heartbeat send error ~p, closing connection",
809812
[Unexpected]),
810813
_C1 = demonitor_all_streams(Connection),
811-
close(Transport, S, State),
812814
stop
813815
end;
814816
open(info, heartbeat_timeout,
@@ -817,7 +819,6 @@ open(info, heartbeat_timeout,
817819
connection_state = State}) ->
818820
rabbit_log_connection:debug("Heartbeat timeout, closing connection"),
819821
_C1 = demonitor_all_streams(Connection),
820-
close(Transport, S, State),
821822
stop;
822823
open(info, {infos, From},
823824
#statem_data{connection =
@@ -857,7 +858,6 @@ open({call, From}, {shutdown, Explanation},
857858
rabbit_log_connection:info("Forcing stream connection ~p closing: ~p",
858859
[self(), Explanation]),
859860
demonitor_all_streams(Connection),
860-
close(Transport, S, State),
861861
{stop_and_reply, normal, {reply, From, ok}};
862862
open(cast,
863863
{queue_event, _, {osiris_written, _, undefined, CorrelationList}},
@@ -1060,7 +1060,6 @@ close_sent(state_timeout, close,
10601060
connection_state = State}) ->
10611061
rabbit_log_connection:warning("Closing connection because of timeout in state '~s' likely due to lack of client action.",
10621062
[?FUNCTION_NAME]),
1063-
close(Transport, Socket, State),
10641063
stop;
10651064
close_sent(info, {tcp, S, Data},
10661065
#statem_data{transport = Transport,
@@ -1075,7 +1074,6 @@ close_sent(info, {tcp, S, Data},
10751074
[?FUNCTION_NAME, Step]),
10761075
case Step of
10771076
closing_done ->
1078-
close(Transport, S, State1),
10791077
stop;
10801078
_ ->
10811079
Transport:setopts(S, [{active, once}]),
@@ -1091,7 +1089,6 @@ close_sent(info, {tcp_error, S, Reason},
10911089
#statem_data{transport = Transport, connection_state = State}) ->
10921090
rabbit_log_connection:error("Stream protocol connection socket error: ~p [~w] [~w]",
10931091
[Reason, S, self()]),
1094-
close(Transport, S, State),
10951092
stop;
10961093
close_sent(info, {resource_alarm, IsThereAlarm},
10971094
StatemData = #statem_data{connection = Connection}) ->

0 commit comments

Comments
 (0)