173
173
callback_mode () ->
174
174
[state_functions , state_enter ].
175
175
176
- terminate (Reason , State , _StatemData ) ->
176
+ terminate (Reason , State , StatemData ) ->
177
+ rabbit_networking :unregister_non_amqp_connection (self ()),
178
+ notify_connection_closed (StatemData ),
177
179
rabbit_log :debug (" ~p terminating in state '~s ' with reason '~p '" , [? MODULE , State , Reason ]).
178
180
179
181
start_link (KeepaliveSup , Transport , Ref , Opts ) ->
@@ -656,8 +658,6 @@ open(info,
656
658
case Step of
657
659
closing ->
658
660
close (Transport , S , State ),
659
- rabbit_networking :unregister_non_amqp_connection (self ()),
660
- notify_connection_closed (Connection1 , State1 ),
661
661
stop ;
662
662
close_sent ->
663
663
rabbit_log_connection :debug (" Transitioned to close_sent" ),
@@ -697,24 +697,14 @@ open(info,
697
697
connection = Connection1 ,
698
698
connection_state = State2 }}
699
699
end ;
700
- open (info , {Closed , Socket }, # statem_data {
701
- connection = Connection ,
702
- connection_state = State
703
- })
700
+ open (info , {Closed , Socket }, # statem_data {connection = Connection })
704
701
when Closed =:= tcp_closed ; Closed =:= ssl_closed ->
705
702
demonitor_all_streams (Connection ),
706
- rabbit_networking :unregister_non_amqp_connection (self ()),
707
- notify_connection_closed (Connection , State ),
708
703
rabbit_log_connection :warning (" Socket ~w closed [~w ]" , [Socket , self ()]),
709
704
stop ;
710
- open (info , {Error , Socket , Reason }, # statem_data {
711
- connection = Connection ,
712
- connection_state = State
713
- })
705
+ open (info , {Error , Socket , Reason }, # statem_data {connection = Connection })
714
706
when Error =:= tcp_error ; Error =:= ssl_error ->
715
707
demonitor_all_streams (Connection ),
716
- rabbit_networking :unregister_non_amqp_connection (self ()),
717
- notify_connection_closed (Connection , State ),
718
708
rabbit_log_connection :error (" Socket error ~p [~w ] [~w ]" , [Reason , Socket , self ()]),
719
709
stop ;
720
710
open (info ,
@@ -813,8 +803,6 @@ open({call, From}, {shutdown, Explanation}, #statem_data{
813
803
rabbit_log_connection :info (" Forcing stream connection ~p closing: ~p " ,
814
804
[self (), Explanation ]),
815
805
demonitor_all_streams (Connection ),
816
- rabbit_networking :unregister_non_amqp_connection (self ()),
817
- notify_connection_closed (Connection , State ),
818
806
close (Transport , S , State ),
819
807
{stop_and_reply , normal , {reply , From , ok }};
820
808
open (cast ,
@@ -1013,15 +1001,13 @@ close_sent(enter, _OldState, #statem_data{
1013
1001
{keep_state_and_data , {state_timeout , StateTimeout , close }};
1014
1002
close_sent (state_timeout , close , # statem_data {
1015
1003
transport = Transport ,
1016
- connection = # stream_connection {socket = Socket } = Connection ,
1004
+ connection = # stream_connection {socket = Socket },
1017
1005
connection_state = State
1018
1006
}) ->
1019
1007
rabbit_log_connection :warning (
1020
1008
" Closing connection because of timeout in state '~s ' likely due to lack of client action." ,
1021
1009
[? FUNCTION_NAME ]),
1022
1010
close (Transport , Socket , State ),
1023
- rabbit_networking :unregister_non_amqp_connection (self ()),
1024
- notify_connection_closed (Connection , State ),
1025
1011
stop ;
1026
1012
close_sent (info , {tcp , S , Data }, # statem_data {
1027
1013
transport = Transport ,
@@ -1037,8 +1023,6 @@ close_sent(info, {tcp, S, Data}, #statem_data{
1037
1023
case Step of
1038
1024
closing_done ->
1039
1025
close (Transport , S , State1 ),
1040
- rabbit_networking :unregister_non_amqp_connection (self ()),
1041
- notify_connection_closed (Connection1 , State1 ),
1042
1026
stop ;
1043
1027
_ ->
1044
1028
Transport :setopts (S , [{active , once }]),
@@ -1047,23 +1031,15 @@ close_sent(info, {tcp, S, Data}, #statem_data{
1047
1031
connection_state = State1
1048
1032
}}
1049
1033
end ;
1050
- close_sent (info , {tcp_closed , S }, # statem_data {
1051
- connection = Connection ,
1052
- connection_state = State
1053
- }) ->
1054
- rabbit_networking :unregister_non_amqp_connection (self ()),
1055
- notify_connection_closed (Connection , State ),
1034
+ close_sent (info , {tcp_closed , S }, _StatemData ) ->
1056
1035
rabbit_log_connection :debug (" Stream protocol connection socket ~w closed [~w ]" , [S , self ()]),
1057
1036
stop ;
1058
1037
close_sent (info , {tcp_error , S , Reason }, # statem_data {
1059
1038
transport = Transport ,
1060
- connection = Connection ,
1061
1039
connection_state = State
1062
1040
}) ->
1063
1041
rabbit_log_connection :error (" Stream protocol connection socket error: ~p [~w ] [~w ]" , [Reason , S , self ()]),
1064
1042
close (Transport , S , State ),
1065
- rabbit_networking :unregister_non_amqp_connection (self ()),
1066
- notify_connection_closed (Connection , State ),
1067
1043
stop ;
1068
1044
close_sent (info ,{resource_alarm , IsThereAlarm },
1069
1045
StatemData = # statem_data {connection = Connection }) ->
@@ -2290,11 +2266,12 @@ handle_frame_post_auth(Transport,
2290
2266
rabbit_global_counters :increase_protocol_counter (stream , ? UNKNOWN_FRAME , 1 ),
2291
2267
{Connection # stream_connection {connection_step = close_sent }, State }.
2292
2268
2293
- notify_connection_closed (# stream_connection {name = Name ,
2294
- publishers = Publishers } =
2295
- Connection ,
2296
- # stream_connection_state {consumers = Consumers } =
2297
- ConnectionState ) ->
2269
+ notify_connection_closed (
2270
+ # statem_data {connection = # stream_connection {
2271
+ name = Name ,
2272
+ publishers = Publishers } = Connection ,
2273
+ connection_state = # stream_connection_state {
2274
+ consumers = Consumers } = ConnectionState }) ->
2298
2275
rabbit_core_metrics :connection_closed (self ()),
2299
2276
[rabbit_stream_metrics :consumer_cancelled (self (),
2300
2277
stream_r (S , Connection ), SubId )
0 commit comments