Skip to content

Commit 78234f0

Browse files
Merge pull request #15995 from rabbitmq/mk-test-flakes-main-apr-9-2026-round-4
Test flake chase: MQTT: fix a very timing-sensitive behavior around Last Will and Testament message delivery
2 parents 2bd0094 + 6f76113 commit 78234f0

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

deps/amqp_client/test/system_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ rpc_client_consume_loop(Channel) ->
10231023
rpc_client_consume_loop(Channel);
10241024
_ ->
10251025
rpc_client_consume_loop(Channel)
1026-
after 5000 ->
1026+
after 30000 ->
10271027
exit(no_request_received)
10281028
end.
10291029

deps/rabbitmq_mqtt/src/rabbit_mqtt_processor.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
-define(MAX_PERMISSION_CACHE_SIZE, 12).
4040
-define(CONSUMER_TAG, <<"mqtt">>).
4141
-define(QUEUE_TTL_KEY, <<"x-expires">>).
42+
-define(WILL_QUEUE_EXPIRY_MARGIN_MS, 1_000).
4243
-define(DEFAULT_EXCHANGE_NAME, <<>>).
4344
-define(FENCE_TIMEOUT, 30_000).
4445

@@ -1812,7 +1813,15 @@ maybe_send_will(
18121813
vhost = Vhost
18131814
}} = State)
18141815
when is_integer(Delay) andalso Delay > 0 andalso SessionExpiry > 0 ->
1815-
QArgs0 = queue_ttl_args(SessionExpiry),
1816+
%% Extend x-expires by a small margin above the Session Expiry Interval
1817+
%% so that the queue-expiry timer cannot race with the message-TTL +
1818+
%% dead-letter path and silently drop the Will Message.
1819+
QArgs0 = case queue_ttl_args(SessionExpiry) of
1820+
[] ->
1821+
[];
1822+
[{Key, Type, TtlMs}] ->
1823+
[{Key, Type, TtlMs + ?WILL_QUEUE_EXPIRY_MARGIN_MS}]
1824+
end,
18161825
QArgs = QArgs0 ++ [{<<"x-dead-letter-exchange">>, longstr, XName},
18171826
{<<"x-dead-letter-routing-key">>, longstr, mqtt_to_amqp(Topic)}],
18181827
T = erlang:monotonic_time(millisecond),

0 commit comments

Comments
 (0)