@@ -140,11 +140,15 @@ handle_cast({close_connection, Reason},
140
140
141
141
handle_cast (QueueEvent = {queue_event , _ , _ },
142
142
State = # state {proc_state = PState0 }) ->
143
- case rabbit_mqtt_processor :handle_queue_event (QueueEvent , PState0 ) of
144
- {ok , PState } ->
145
- maybe_process_deferred_recv (control_throttle (pstate (State , PState )));
146
- {error , Reason , PState } ->
147
- {stop , Reason , pstate (State , PState )}
143
+ try
144
+ case rabbit_mqtt_processor :handle_queue_event (QueueEvent , PState0 ) of
145
+ {ok , PState } ->
146
+ maybe_process_deferred_recv (control_throttle (pstate (State , PState )));
147
+ {error , Reason0 , PState } ->
148
+ {stop , Reason0 , pstate (State , PState )}
149
+ end
150
+ catch throw :{send_failed , Reason1 } ->
151
+ network_error (Reason1 , State )
148
152
end ;
149
153
150
154
handle_cast ({force_event_refresh , Ref }, State0 ) ->
@@ -328,17 +332,17 @@ process_received_bytes(Bytes, State = #state{socket = Socket,
328
332
{ok , Packet , Rest , ParseState1 } ->
329
333
case ProcState of
330
334
connect_packet_unprocessed ->
331
- Send = fun (Data ) ->
332
- case rabbit_net :send (Socket , Data ) of
333
- ok ->
334
- ok ;
335
- {error , Reason } ->
336
- ? LOG_ERROR (" writing to MQTT socket ~p failed: ~p " ,
337
- [Socket , Reason ]),
338
- exit ({send_failed , Reason })
339
- end
340
- end ,
341
- try rabbit_mqtt_processor :init (Packet , Socket , ConnName , Send ) of
335
+ SendFun = fun (Data ) ->
336
+ case rabbit_net :send (Socket , Data ) of
337
+ ok ->
338
+ ok ;
339
+ {error , Reason } ->
340
+ ? LOG_ERROR (" writing to MQTT socket ~p failed: ~p " ,
341
+ [Socket , Reason ]),
342
+ throw ({send_failed , Reason })
343
+ end
344
+ end ,
345
+ try rabbit_mqtt_processor :init (Packet , Socket , ConnName , SendFun ) of
342
346
{ok , ProcState1 } ->
343
347
? LOG_INFO (" Accepted MQTT connection ~ts for client ID ~ts " ,
344
348
[ConnName , rabbit_mqtt_processor :info (client_id , ProcState1 )]),
@@ -354,7 +358,7 @@ process_received_bytes(Bytes, State = #state{socket = Socket,
354
358
? LOG_ERROR (" Rejected MQTT connection ~ts with Connect Reason Code ~p " ,
355
359
[ConnName , ConnectReasonCode ]),
356
360
{stop , shutdown , {_SendWill = false , State }}
357
- catch exit :{send_failed , Reason } ->
361
+ catch throw :{send_failed , Reason } ->
358
362
network_error (Reason , State )
359
363
end ;
360
364
_ ->
@@ -375,7 +379,7 @@ process_received_bytes(Bytes, State = #state{socket = Socket,
375
379
{stop , {shutdown , Reason }, pstate (State , ProcState1 )};
376
380
{stop , {disconnect , {client_initiated , SendWill }}, ProcState1 } ->
377
381
{stop , normal , {SendWill , pstate (State , ProcState1 )}}
378
- catch exit :{send_failed , Reason } ->
382
+ catch throw :{send_failed , Reason } ->
379
383
network_error (Reason , State )
380
384
end
381
385
end ;
0 commit comments