Skip to content

Commit f6b2f82

Browse files
bramweltclaude
andcommitted
fix(review): address PR #25 review feedback
Address review comment from copilot-pull-request-reviewer[bot]: - messaging_repository.go: flatten ctx-deadline/timeout guard so that a caller-supplied timeout <= 0 is also caught. Previously, the nested `remaining < timeout` condition was false when timeout was negative and remaining was positive, silently passing an invalid duration to RequestMsg. Now: always clamp to ctx deadline when shorter, then a single `timeout <= 0` guard short-circuits with context.DeadlineExceeded before reaching NATS. Resolves 1 review thread. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Issue: LFXV2-1743 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
1 parent bee59f9 commit f6b2f82

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

internal/infrastructure/messaging/messaging_repository.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ func (r *messagingRepository) Request(ctx context.Context, subject string, data
116116
return nil, constants.ErrNATSConnNotInit
117117
}
118118

119-
// Use the shorter of the explicit timeout and any deadline already on ctx.
120-
// If the deadline is already past, short-circuit rather than passing a
121-
// negative duration to RequestMsg.
119+
// Clamp timeout to the ctx deadline if it is shorter.
122120
if deadline, ok := ctx.Deadline(); ok {
123121
if remaining := time.Until(deadline); remaining < timeout {
124-
if remaining <= 0 {
125-
span.RecordError(context.DeadlineExceeded)
126-
span.SetStatus(codes.Error, context.DeadlineExceeded.Error())
127-
return nil, context.DeadlineExceeded
128-
}
129122
timeout = remaining
130123
}
131124
}
125+
// Short-circuit if timeout is zero or negative — either the caller passed
126+
// an invalid duration or the ctx deadline was already past.
127+
if timeout <= 0 {
128+
span.RecordError(context.DeadlineExceeded)
129+
span.SetStatus(codes.Error, context.DeadlineExceeded.Error())
130+
return nil, context.DeadlineExceeded
131+
}
132132

133133
natsMsg := nats.NewMsg(subject)
134134
natsMsg.Data = data

0 commit comments

Comments
 (0)