Commit 76d1ac5
fix: prevent panic on SSE reverse proxy when backend closes connection (#128)
* fix: prevent panic on SSE reverse proxy when backend closes connection
The default httputil.ReverseProxy panics with "net/http: abort Handler"
when proxying SSE (Server-Sent Events) streams and the backend closes
the connection. This happens frequently with MCP Streamable HTTP
backends (e.g. n8n) when sessions expire or clients disconnect.
Add ErrorHandler to log the error instead of panicking, and set
FlushInterval to -1 for immediate SSE flushing.
Fixes the panic at reverseproxy.go:543 in handleProxy (proxy.go:90).
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* fix: recover from ErrAbortHandler panic in SSE proxy handler
The previous ErrorHandler fix in transparent.go only covers transport
errors. The actual panic at reverseproxy.go:543 is http.ErrAbortHandler
triggered during response flush when an SSE stream ends. This panic
bypasses ErrorHandler entirely.
Add a deferred recover() in proxy.go's handleProxy to catch
ErrAbortHandler panics silently (they are expected for SSE) while
re-panicking on unexpected errors.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>1 parent 9803d0f commit 76d1ac5
2 files changed
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
128 | 149 | | |
129 | 150 | | |
130 | 151 | | |
| |||
147 | 168 | | |
148 | 169 | | |
149 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
150 | 182 | | |
151 | 183 | | |
152 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
90 | 106 | | |
91 | 107 | | |
92 | 108 | | |
| |||
0 commit comments