Commit 8c90e8b
Fix EXPIRE family emitting two replies for incompatible options (#2037)
NetworkEXPIRE wrote the "NX and XX, GT or LT options at the same time are
not compatible" error and then fell through to storageApi.EXPIRE, so a
rejected command produced two RESP replies and applied the expiry it had
just refused.
Measured on a Debug build of 8b329e3 over a raw socket, for EXPIRE,
PEXPIRE, EXPIREAT and PEXPIREAT with "NX XX", and for EXPIRE with
"GT LT":
SET keyA valueA ; EXPIRE keyA 100 NX XX
-> -ERR ...not compatible\r\n:1\r\n (two replies for one command)
TTL keyA -> :100 (the refused expiry was applied)
SET keyB valueB ; EXPIRE keyB 0 NX XX
-> -ERR ...not compatible\r\n:1\r\n
EXISTS keyB -> :0 (the key was deleted)
Return via AbortWithErrorMessage instead, matching the five other
validation failures in the same method. The wire text is unchanged: the
ReadOnlySpan<byte> overload emits '-' + payload + CRLF exactly as the
ReadOnlySpan<char> one did for this ASCII literal.
The neighbouring "Unsupported option" message reported the wrong token:
it formatted token 2 while validating token 3, so "EXPIRE keyA 100 NX ZZ"
answered "-ERR Unsupported option NX" and named the option that was
valid. Both call sites now pass the token to AbortWithErrorMessage rather
than pre-formatting it. That also fixes a session kill: a single string
argument binds to the params object[] overload, which runs string.Format
a second time over the already-substituted text, so a brace in the
rejected option threw FormatException out of the handler:
EXPIRE keyA 100 { -> b'' (no reply, connection closed)
EXPIRE keyA 100 { -> -ERR Unsupported option { (after)
Pre-formatting only token 2 is why "EXPIRE keyA 100 NX {" escaped this
today; correcting the token index without also removing the second format
would have extended the crash to it.
One further behaviour change worth noting: AbortWithErrorMessage sets
commandErrorWritten, which the raw TryWriteError call it replaces did
not, so this rejection now counts toward INFO commandstats failed_calls
the way every other validation failure in the method already does.
Co-authored-by: kevin-montrose <kmontrose@microsoft.com>1 parent 7062722 commit 8c90e8b
2 files changed
Lines changed: 90 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | | - | |
| 390 | + | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
| 397 | + | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
| 415 | + | |
419 | 416 | | |
420 | 417 | | |
421 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2740 | 2740 | | |
2741 | 2741 | | |
2742 | 2742 | | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
2743 | 2830 | | |
2744 | 2831 | | |
2745 | 2832 | | |
| |||
0 commit comments