Commit a4d268a
committed
fix: SSE onerror should not poison EventSource lifetime with isAuthRetry
The isAuthRetry parameter approach works for recursive method calls
(send, _startOrAuthSse) but not for the EventSource onerror callback.
Passing _startOrAuth(true) on retry permanently captures isAuthRetry=true
in the new EventSource's closure — if that EventSource auto-reconnects
later (network blip on a long-lived stream) and gets 401, onUnauthorized
is skipped and the transport cannot recover.
Verified against eventsource lib: non-200 → failConnection (CLOSED, no
reconnect); stream end after OPEN → scheduleReconnect → reconnect attempt
can get 401 → failConnection → onerror fires. The 'hours later' scenario
is real.
Fix: retry always calls _startOrAuth() fresh (no parameter). Matches
pre-PR _authThenStart() behavior. Trade-off: no circuit breaker on the
SSE connect path — if onUnauthorized succeeds but server keeps 401ing,
it loops (same as pre-PR).
Also fixes double-onerror: two-arg .then(onSuccess, onFail) separates
retry failures (inner _startOrAuth already fired onerror) from
onUnauthorized failures (not yet reported). Added close + clear
_last401Response before retry for hygiene.
Two regression tests added, both verified to FAIL against the buggy
code:
- 401→401→200: onUnauthorized called TWICE, start() resolves
- 401→onUnauthorized succeeds→401→onUnauthorized throws: onerror
fires ONCE with the thrown error1 parent af605e8 commit a4d268a
2 files changed
+83
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | | - | |
| 161 | + | |
| 162 | + | |
159 | 163 | | |
160 | 164 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1624 | 1624 | | |
1625 | 1625 | | |
1626 | 1626 | | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
1627 | 1698 | | |
1628 | 1699 | | |
0 commit comments