Commit 7f3a643
committed
fix(sqs): buildSQSPartitionResolver returns interface to avoid typed-nil
Round 1 Claude review on PR #715 caught a typed-nil interface bug:
buildSQSPartitionResolver had return type *adapter.SQSPartitionResolver,
so on a non-partitioned cluster it returned a typed-nil pointer.
When that pointer was passed into kv.ShardRouter.WithPartitionResolver
(parameter type kv.PartitionResolver), Go wrapped it into a NON-NIL
interface — the resolver-first short-circuit
`s.partitionResolver != nil` would always pass on every request,
defeating the "non-partitioned cluster keeps engine-only hot path"
contract from the PR description.
The (*SQSPartitionResolver).ResolveGroup nil-receiver guard kept this
functionally safe (correct routing) but not free (extra map lookup
per request).
Fix
- Return type changed from *adapter.SQSPartitionResolver to
kv.PartitionResolver. Untyped `nil` returns now propagate as a
true nil interface, the short-circuit fires correctly, and the
hot path stays engine-only.
- Defensive nil guard after NewSQSPartitionResolver in case
canonicalisation collapses every entry — the typed pointer from
the constructor would otherwise wrap to a non-nil interface
even when its underlying pointer is nil.
- New main_sqs_resolver_test.go regression test:
TestBuildSQSPartitionResolver_NilOnEmpty uses requireNilInterface
to force the kv.PartitionResolver conversion at the call boundary
(a plain require.Nil on the concrete pointer would pass even with
the bug present, since the pointer itself IS nil — only the
interface wrap exposes the failure mode).
- TestBuildSQSPartitionResolver_NonEmptyReturnsResolver pins the
happy path so a future "always return nil" regression is caught.1 parent 8bbfcb9 commit 7f3a643
2 files changed
Lines changed: 93 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
489 | 500 | | |
490 | 501 | | |
491 | 502 | | |
492 | 503 | | |
493 | 504 | | |
494 | 505 | | |
495 | | - | |
| 506 | + | |
496 | 507 | | |
497 | 508 | | |
498 | 509 | | |
| |||
514 | 525 | | |
515 | 526 | | |
516 | 527 | | |
517 | | - | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
518 | 538 | | |
519 | 539 | | |
520 | 540 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
0 commit comments