Skip to content

fix: use TotalSeconds/TotalMilliseconds in WaitAndRetry timeout comparison#134

Merged
mattburton merged 1 commit into
mainfrom
fix/timeout-comparison-uses-wrong-timespan-properties
May 27, 2026
Merged

fix: use TotalSeconds/TotalMilliseconds in WaitAndRetry timeout comparison#134
mattburton merged 1 commit into
mainfrom
fix/timeout-comparison-uses-wrong-timespan-properties

Conversation

@mattburton
Copy link
Copy Markdown
Contributor

Problem

WaitAndRetry uses config.Timeout.Seconds and config.Timeout.Milliseconds to decide whether a retry-after delay exceeds the configured timeout. These properties return only the component of the TimeSpan (0-59 for seconds, 0-999 for milliseconds), not the total value.

For the default timeout of 60 seconds (TimeSpan.FromSeconds(60)):

  • .Seconds0 (because it's exactly 1 minute)
  • .Milliseconds0

This means any 429 response with a RetryAfter header > 0 will immediately throw a ShipEngineException with the misleading message:

The request took longer than the 0 milliseconds allowed

...instead of actually retrying the request.

Fix

Replace .Seconds with .TotalSeconds and .Milliseconds with .TotalMilliseconds.

Tests

Added two regression tests:

  1. RetryWorksWithTimeoutGreaterThanOrEqualTo60Seconds — verifies that a 60s timeout correctly retries on 429 instead of throwing
  2. TimeoutMessageShowsCorrectMillisecondsForLargeTimeouts — verifies the error message reports the correct total milliseconds

@mattburton mattburton force-pushed the fix/timeout-comparison-uses-wrong-timespan-properties branch from 3df3fa1 to 2ad7077 Compare May 27, 2026 15:27
…rison

TimeSpan.Seconds returns only the seconds component (0-59), not the
total seconds. For timeouts >= 60 seconds (e.g. the default 60s),
.Seconds is 0 because it's exactly 1 minute. This caused WaitAndRetry
to always throw a timeout exception instead of retrying, with the
misleading message 'The request took longer than the 0 milliseconds
allowed'.

The fix uses .TotalSeconds and .TotalMilliseconds which return the
full value regardless of magnitude.

Added regression tests for timeouts >= 60s and correct millisecond
reporting in error messages.

Bumps version to 3.2.1.
@mattburton mattburton force-pushed the fix/timeout-comparison-uses-wrong-timespan-properties branch from 2ad7077 to 396e1a1 Compare May 27, 2026 15:31
@mattburton mattburton merged commit ff04c26 into main May 27, 2026
7 checks passed
@mattburton mattburton deleted the fix/timeout-comparison-uses-wrong-timespan-properties branch May 27, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants