Skip to content

Commit 9bd0697

Browse files
Introduce a way to disable FHC use in web_stomp
1 parent 3339e8d commit 9bd0697

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

deps/rabbitmq_web_stomp/priv/schema/rabbitmq_web_stomp.schema

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,12 @@ end}.
189189

190190
{mapping, "web_stomp.proxy_protocol", "rabbitmq_web_stomp.proxy_protocol",
191191
[{datatype, {enum, [true, false]}}]}.
192+
193+
%%
194+
%% File Handle Cache
195+
%%
196+
197+
{mapping, "web_stomp.enable_file_handle_cache", "rabbitmq_web_stomp.enable_file_handle_cache",
198+
[
199+
{datatype, {enum, [true, false]}}
200+
]}.

deps/rabbitmq_web_stomp/src/rabbit_web_stomp_handler.erl

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
-behaviour(cowboy_websocket).
1010
-behaviour(cowboy_sub_protocol).
1111

12+
-include_lib("kernel/include/logger.hrl").
13+
-include_lib("rabbit_common/include/logging.hrl").
1214
-include_lib("rabbitmq_stomp/include/rabbit_stomp.hrl").
1315
-include_lib("rabbitmq_stomp/include/rabbit_stomp_frame.hrl").
1416
-include_lib("amqp_client/include/amqp_client.hrl").
@@ -41,9 +43,12 @@
4143
peername,
4244
auth_hd,
4345
stats_timer,
44-
connection
46+
connection,
47+
should_use_fhc :: rabbit_types:option(boolean())
4548
}).
4649

50+
-define(APP, rabbitmq_web_stomp).
51+
4752
%% cowboy_sub_protcol
4853
upgrade(Req, Env, Handler, HandlerState) ->
4954
upgrade(Req, Env, Handler, HandlerState, #{}).
@@ -80,6 +85,11 @@ init(Req0, Opts) ->
8085
end,
8186
WsOpts0 = proplists:get_value(ws_opts, Opts, #{}),
8287
WsOpts = maps:merge(#{compress => true}, WsOpts0),
88+
ShouldUseFHC = application:get_env(?APP, enable_file_handle_cache, true),
89+
case ShouldUseFHC of
90+
true -> ?LOG_INFO("Web STOMP: file handle cache use is enabled");
91+
false -> ?LOG_INFO("Web STOMP: file handle cache use is disabled")
92+
end,
8393
{?MODULE, Req, #state{
8494
frame_type = proplists:get_value(type, Opts, text),
8595
heartbeat_sup = KeepaliveSup,
@@ -89,11 +99,18 @@ init(Req0, Opts) ->
8999
conserve_resources = false,
90100
socket = SockInfo,
91101
peername = PeerAddr,
92-
auth_hd = cowboy_req:header(<<"authorization">>, Req)
102+
auth_hd = cowboy_req:header(<<"authorization">>, Req),
103+
should_use_fhc = ShouldUseFHC
93104
}, WsOpts}.
94105

95-
websocket_init(State) ->
96-
ok = file_handle_cache:obtain(),
106+
websocket_init(State = #state{should_use_fhc = ShouldUseFHC}) ->
107+
case ShouldUseFHC of
108+
true ->
109+
ok = file_handle_cache:obtain();
110+
false -> ok;
111+
undefined ->
112+
ok = file_handle_cache:obtain()
113+
end,
97114
process_flag(trap_exit, true),
98115
{ok, ProcessorState} = init_processor_state(State),
99116
{ok, rabbit_event:init_stats_timer(
@@ -314,9 +331,15 @@ maybe_block(State, _) ->
314331
stop(State) ->
315332
stop(State, 1000, "STOMP died").
316333

317-
stop(State = #state{proc_state = ProcState}, CloseCode, Error0) ->
334+
stop(State = #state{proc_state = ProcState, should_use_fhc = ShouldUseFHC}, CloseCode, Error0) ->
318335
maybe_emit_stats(State),
319-
ok = file_handle_cache:release(),
336+
case ShouldUseFHC of
337+
true ->
338+
ok = file_handle_cache:release();
339+
false -> ok;
340+
undefined ->
341+
ok = file_handle_cache:release()
342+
end,
320343
_ = rabbit_stomp_processor:flush_and_die(ProcState),
321344
Error1 = rabbit_data_coercion:to_binary(Error0),
322345
{[{close, CloseCode, Error1}], State}.

deps/rabbitmq_web_stomp/test/config_schema_SUITE_data/rabbitmq_web_stomp.snippets

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@
4242
[{max_connections, 5000}]}],
4343
[rabbitmq_web_stomp]},
4444

45+
{enable_file_handle_cache_is_disabled,
46+
"web_stomp.enable_file_handle_cache = false",
47+
[{rabbitmq_web_stomp,
48+
[{enable_file_handle_cache, false}]}],
49+
[rabbitmq_web_stomp]},
50+
51+
{enable_file_handle_cache_is_enabled,
52+
"web_stomp.enable_file_handle_cache = true",
53+
[{rabbitmq_web_stomp,
54+
[{enable_file_handle_cache, true}]}],
55+
[rabbitmq_web_stomp]},
56+
4557
{ssl_listener,
4658
"web_stomp.ssl.listener = 127.0.0.4:15672",
4759
[{rabbitmq_web_stomp,

0 commit comments

Comments
 (0)