fix(retry): prevent replay amplification and isolate backoff (NAN-313)

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-29 11:13:44 +08:00
1 parent b6d9009bb4
commit 4e77d9c3f2
19 files changed
+1178 -587

No files matched your search

+8
View File
@@ -2997,6 +2997,7 @@ async def test_send_with_retry_succeeds_first_try():
mgr.bus = MessageBus()
mgr.channels = {"failing": _FailingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = OutboundMessage(channel="failing", chat_id="123", content="test")
await mgr._send_with_retry(mgr.channels["failing"], msg)
@@ -3034,6 +3035,7 @@ async def test_send_with_retry_retries_on_failure():
mgr.bus = MessageBus()
mgr.channels = {"failing": _FailingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = OutboundMessage(channel="failing", chat_id="123", content="test")
@@ -3075,6 +3077,7 @@ async def test_send_with_retry_no_retry_when_max_is_zero():
mgr.bus = MessageBus()
mgr.channels = {"failing": _FailingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = OutboundMessage(channel="failing", chat_id="123", content="test")
@@ -3125,6 +3128,7 @@ async def test_send_with_retry_calls_send_delta():
mgr.bus = MessageBus()
mgr.channels = {"streaming": _StreamingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = outbound_message_for_event(
channel="streaming",
@@ -3193,6 +3197,7 @@ async def test_send_with_retry_skips_send_when_streamed():
mgr.bus = MessageBus()
mgr.channels = {"streamed": _StreamedChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = outbound_message_for_event(
channel="streamed",
@@ -3309,6 +3314,7 @@ async def test_send_with_retry_propagates_cancelled_error():
mgr.bus = MessageBus()
mgr.channels = {"cancelling": _CancellingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = OutboundMessage(channel="cancelling", chat_id="123", content="test")
@@ -3346,6 +3352,7 @@ async def test_send_with_retry_propagates_cancelled_error_during_sleep():
mgr.bus = MessageBus()
mgr.channels = {"failing": _FailingChannel(fake_config, mgr.bus)}
mgr._dispatch_task = None
mgr._outbound_sends = asyncio.Semaphore(32)
msg = OutboundMessage(channel="failing", chat_id="123", content="test")
@@ -3837,6 +3844,7 @@ async def test_restart_notice_retries_until_running_channel_accepts_delivery():
mgr = ChannelManager.__new__(ChannelManager)
mgr.config = fake_config
mgr.bus = MessageBus()
mgr._outbound_sends = asyncio.Semaphore(32)
channel = _EventuallyDeliverableChannel(fake_config, mgr.bus)
channel._running = True
mgr.channels = {"discord": channel}