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

Provide clear error message for reserved annotation keys #12523

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test-make-target.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions/setup-dotnet@v4
if: inputs.plugin == 'rabbit'
with:
dotnet-version: '3.1.x'
dotnet-version: '8.0'

- name: SETUP SLAPD (rabbitmq_auth_backend_ldap)
if: inputs.plugin == 'rabbitmq_auth_backend_ldap'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- uses: actions/setup-dotnet@v4
if: inputs.plugin == 'rabbit'
with:
dotnet-version: '3.1.x'
dotnet-version: '8.0'
- name: deps/amqp10_client SETUP
if: inputs.plugin == 'amqp10_client'
run: |
Expand Down
6 changes: 4 additions & 2 deletions deps/amqp10_common/src/amqp10_framing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ decode_map(Fields) ->
%% or of type ulong. All ulong keys, and all symbolic keys except those beginning
%% with "x-" are reserved." [3.2.10]
%% Since we already parse annotations here and neither the client nor server uses
%% reserved keys, we perform strict validation and crash if any reserved keys are used.
%% reserved keys, we perform strict validation and throw if any reserved keys are used.
decode_annotations(Fields) ->
lists:map(fun({{symbol, <<"x-", _/binary>>} = K, V}) ->
{K, decode(V)}
{K, decode(V)};
({ReservedKey, _V}) ->
throw({reserved_annotation_key, ReservedKey})
end, Fields).

-spec encode_described(list | map | binary | annotations | '*',
Expand Down
12 changes: 8 additions & 4 deletions deps/rabbit/src/rabbit_amqp_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,16 @@ handle_cast({frame_body, FrameBody},
noreply(State);
{stop, _, _} = Stop ->
Stop
catch exit:#'v1_0.error'{} = Error ->
log_error_and_close_session(Error, State0);
exit:normal ->
catch exit:normal ->
{stop, normal, State0};
exit:#'v1_0.error'{} = Error ->
log_error_and_close_session(Error, State0);
_:Reason:Stacktrace ->
{stop, {Reason, Stacktrace}, State0}
Description = unicode:characters_to_binary(
lists:flatten(io_lib:format("~tp~n~tp", [Reason, Stacktrace]))),
Err = #'v1_0.error'{condition = ?V_1_0_AMQP_ERROR_INTERNAL_ERROR,
description = {utf8, Description}},
log_error_and_close_session(Err, State0)
end;
handle_cast({queue_event, _, _} = QEvent, State0) ->
try handle_queue_event(QEvent, State0) of
Expand Down
29 changes: 28 additions & 1 deletion deps/rabbit/test/amqp_client_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ groups() ->
tcp_back_pressure_rabbitmq_internal_flow_classic_queue,
tcp_back_pressure_rabbitmq_internal_flow_quorum_queue,
session_max_per_connection,
link_max_per_session
link_max_per_session,
reserved_annotation
]},

{cluster_size_3, [shuffle],
Expand Down Expand Up @@ -5917,6 +5918,32 @@ link_max_per_session(Config) ->
flush(test_succeeded),
ok = rpc(Config, application, set_env, [App, Par, Default]).

reserved_annotation(Config) ->
OpnConf = connection_config(Config),
{ok, Connection} = amqp10_client:open_connection(OpnConf),
{ok, Session} = amqp10_client:begin_session(Connection),
TargetAddr = rabbitmq_amqp_address:exchange(<<"amq.fanout">>),
{ok, Sender} = amqp10_client:attach_sender_link_sync(
Session, <<"sender">>, TargetAddr, settled),
ok = wait_for_credit(Sender),

Msg = amqp10_msg:set_message_annotations(
#{<<"reserved-key">> => 1},
amqp10_msg:new(<<"tag">>, <<"payload">>, true)),
ok = amqp10_client:send_msg(Sender, Msg),
receive
{amqp10_event,
{session, Session,
{ended,
#'v1_0.error'{description = {utf8, Description}}}}} ->
?assertMatch(
<<"{reserved_annotation_key,{symbol,<<\"reserved-key\">>}}", _/binary>>,
Description)
after 5000 -> flush(missing_ended),
ct:fail({missing_event, ?LINE})
end,
ok = close_connection_sync(Connection).

%% internal
%%

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1"
"version": "8.0"
}
}
Loading