Commit f726981
committed
fix(redis,stream): XADD '*' avoids 0-0 when clock is pre-epoch
Gemini medium + Codex P2 round 1 on PR #631: the original change
clamped a pre-epoch clock to nowMs=0 via safeUnixMilliToUint64, but on
a fresh stream the auto-ID branch then returned "0-0" — the very ID
the same function rejects as invalid for explicitly-requested IDs and
which XREAD ... 0 treats as the empty after-marker.
Fix: extract the auto-ID branch into autoXAddID(nowMs, hasLast, ...)
so it can be unit-tested without the wall clock; bump seq to 1 when
nowMs is 0 so the first auto-generated entry is "0-1" rather than
"0-0". The existing bumpStreamID-on-collision path is unchanged.
Tests:
- TestAutoXAddID covers the fresh-stream branch (sane clock, clamped
clock → 0-1), the same-ms collision (bump to seq+1), the
clock-behind-lastMs case (carry from lastMs/lastSeq, not nowMs),
the seq-at-MaxUint64 carry to ms+1, and the ID-space-exhausted
error.
Build / vet / lint clean.1 parent 0a969c3 commit f726981
2 files changed
Lines changed: 81 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3702 | 3702 | | |
3703 | 3703 | | |
3704 | 3704 | | |
| 3705 | + | |
| 3706 | + | |
3705 | 3707 | | |
3706 | | - | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
3707 | 3727 | | |
3708 | | - | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
3709 | 3733 | | |
3710 | 3734 | | |
3711 | 3735 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
0 commit comments