From ec54e3ee601be60ed77125f93dc53e471e0b3d75 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Sun, 17 Nov 2024 22:17:56 -0800 Subject: [PATCH] Ignore exceptions when publishing messages to some subscriber. (#810) --- libs/server/Resp/PubSubCommands.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libs/server/Resp/PubSubCommands.cs b/libs/server/Resp/PubSubCommands.cs index 71c79d0417..89a9dc526d 100644 --- a/libs/server/Resp/PubSubCommands.cs +++ b/libs/server/Resp/PubSubCommands.cs @@ -44,6 +44,10 @@ public override unsafe void Publish(ref byte* keyPtr, int keyLength, ref byte* v if (dcurr > networkSender.GetResponseObjectHead()) Send(networkSender.GetResponseObjectHead()); } + catch + { + // Ignore exceptions + } finally { networkSender.ExitAndReturnResponseObject(); @@ -68,16 +72,19 @@ public override unsafe void PrefixPublish(byte* patternPtr, int patternLength, r } while (!RespWriteUtils.WriteBulkString("pmessage"u8, ref dcurr, dend)) SendAndReset(); - while (!RespWriteUtils.WriteBulkString(new Span(patternPtr + sizeof(int), patternLength - sizeof(int)), ref dcurr, dend)) - SendAndReset(); - while (!RespWriteUtils.WriteBulkString(new Span(keyPtr + sizeof(int), keyLength - sizeof(int)), ref dcurr, dend)) - SendAndReset(); - while (!RespWriteUtils.WriteBulkString(new Span(valPtr + sizeof(int), valLength - sizeof(int)), ref dcurr, dend)) - SendAndReset(); + + // Write pattern, key, and value to the network + WriteDirectLargeRespString(new Span(patternPtr + sizeof(int), patternLength - sizeof(int))); + WriteDirectLargeRespString(new Span(keyPtr + sizeof(int), keyLength - sizeof(int))); + WriteDirectLargeRespString(new Span(valPtr + sizeof(int), valLength - sizeof(int))); if (dcurr > networkSender.GetResponseObjectHead()) Send(networkSender.GetResponseObjectHead()); } + catch + { + // Ignore exceptions + } finally { networkSender.ExitAndReturnResponseObject();