Commit 2e16971
committed
internal/jsonrpc2: plumb cancellation cause through request context
handleAsync reported why a request was canceled by inspecting the
connection-level s.writeErr, guarded by a TODO awaiting golang/go#51365.
That API shipped as context.WithCancelCause/context.Cause in Go 1.21, and
this module targets Go 1.25.
Carry the cancellation cause on each request's context instead of inferring
it from global state. Both the write-failure and read-side teardowns cancel
each in-flight request with a cause wrapping ErrServerClosing; the remaining
cancel sites (peer cancel, normal completion) pass nil. handleAsync now reads
context.Cause(req.ctx) instead of guessing from s.writeErr.
This also fixes a latent mis-attribution: s.writeErr is connection-level, so
a request canceled for an unrelated reason was reported as ErrServerClosing
whenever s.writeErr happened to be non-nil. ctx.Err() still returns
context.Canceled in all cases, so external behavior for callers inspecting
ctx.Err() is unchanged.1 parent ce393ac commit 2e16971
1 file changed
Lines changed: 13 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
| |||
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
| 557 | + | |
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
567 | | - | |
| 567 | + | |
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
668 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
669 | 672 | | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
677 | 676 | | |
678 | 677 | | |
679 | 678 | | |
| |||
734 | 733 | | |
735 | 734 | | |
736 | 735 | | |
737 | | - | |
| 736 | + | |
738 | 737 | | |
739 | 738 | | |
740 | 739 | | |
| |||
777 | 776 | | |
778 | 777 | | |
779 | 778 | | |
780 | | - | |
| 779 | + | |
781 | 780 | | |
782 | 781 | | |
783 | 782 | | |
| |||
0 commit comments