Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add direct reply subject checks
  • Loading branch information
mtmk committed Apr 15, 2025
commit e1c1d92bb590d09b6e6cb2081e47ca3d11de81fe
5 changes: 4 additions & 1 deletion src/NATS.Client.Core/Internal/ReplyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ public ReplyTask<TReply> CreateReplyTask<TReply>(INatsDeserialize<TReply>? deser

public void Return(long id) => _replies.TryRemove(id, out _);

public void SetResult(long id, string? replyTo, in ReadOnlySequence<byte> payloadBuffer, in ReadOnlySequence<byte>? headersBuffer)
public bool TrySetResult(long id, string? replyTo, in ReadOnlySequence<byte> payloadBuffer, in ReadOnlySequence<byte>? headersBuffer)
{
if (_replies.TryGetValue(id, out var rt))
{
rt.SetResult(replyTo, payloadBuffer, headersBuffer);
return true;
}

return false;
}
}
9 changes: 7 additions & 2 deletions src/NATS.Client.Core/NatsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,13 @@ internal ValueTask PublishToClientHandlersAsync(string subject, string? replyTo,

if (long.TryParse(idString, out var id))
{
_replyTaskFactory.SetResult(id, replyTo, payloadBuffer, headersBuffer);
return default;
if (_replyTaskFactory.TrySetResult(id, replyTo, payloadBuffer, headersBuffer))
{
return default;
}

// if we can't set the result, either the task is already timed out or
// it's not a reply to a request.
}

// if we can't parse the id, it's not a reply.
Expand Down