Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web-MQTT: don't call FHC when connection terminates early #9654

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ init(Req, Opts) ->
undefined ->
no_supported_sub_protocol(undefined, Req);
Protocol ->
WsOpts0 = proplists:get_value(ws_opts, Opts, #{}),
WsOpts = maps:merge(#{compress => true}, WsOpts0),
case lists:member(<<"mqtt">>, Protocol) of
false ->
no_supported_sub_protocol(Protocol, Req);
true ->
WsOpts0 = proplists:get_value(ws_opts, Opts, #{}),
WsOpts = maps:merge(#{compress => true}, WsOpts0),
ShouldUseFHC = application:get_env(?APP, use_file_handle_cache, true),
case ShouldUseFHC of
true -> ?LOG_INFO("Web MQTT: file handle cache use is enabled");
Expand Down Expand Up @@ -278,7 +278,12 @@ terminate(_Reason, _Request,
no_supported_sub_protocol(Protocol, Req) ->
%% The client MUST include “mqtt” in the list of WebSocket Sub Protocols it offers [MQTT-6.0.0-3].
?LOG_ERROR("Web MQTT: 'mqtt' not included in client offered subprotocols: ~tp", [Protocol]),
{ok, cowboy_req:reply(400, #{<<"connection">> => <<"close">>}, Req), #state{}}.
%% Set should_use_fhc to false, because at this early stage of init no fhc
%% obtain was called, so terminate/3 should not call fhc release
%% (even if use_file_handle_cache is true)
{ok,
cowboy_req:reply(400, #{<<"connection">> => <<"close">>}, Req),
#state{should_use_fhc = false}}.

handle_data(Data, State0 = #state{}) ->
case handle_data1(Data, State0) of
Expand Down