Commit 3671534
authored
fix(proxy): clear SNI peek deadline before relay, fix socket leaks (#15)
The 10-second read deadline set for SNI peeking in the SNI-deferred
path was cleared via defer, which only runs when handleConnect returns.
Since handleConnect blocks in relayData for the connection lifetime,
the deadline persisted and killed every SNI-deferred connection after
10 seconds. This caused streaming API responses to be truncated
(manifesting as OpenAI "terminated" errors), tool call fetches to fail,
and periodic TLS handshake failures on chatgpt.com.
Fix: clear the deadline explicitly after SNI peek completes, before
the relay phase begins.
Also fixes two secondary issues:
- relayData socket leak: when the first relay direction completed,
the function could block indefinitely waiting for the second
goroutine if goproxy held the MITM connection open. Close writer
and set a read deadline on target to force cleanup. Eliminates
CLOSE_WAIT socket accumulation (75 leaked sockets observed).
- goproxy Transport stale connections: the MITM proxy Transport had
no IdleConnTimeout, causing dead pooled connections to persist
indefinitely. Add IdleConnTimeout (90s) and MaxIdleConnsPerHost (4).
- goproxy log noise: suppress expected broken pipe and handshake EOF
warnings via a filtered logger. These are normal for short-lived
polling connections (Telegram getUpdates).1 parent b643af1 commit 3671534
2 files changed
Lines changed: 60 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
| |||
177 | 196 | | |
178 | 197 | | |
179 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
180 | 206 | | |
181 | 207 | | |
182 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1111 | 1111 | | |
1112 | 1112 | | |
1113 | 1113 | | |
1114 | | - | |
1115 | 1114 | | |
1116 | 1115 | | |
1117 | 1116 | | |
| |||
1120 | 1119 | | |
1121 | 1120 | | |
1122 | 1121 | | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1123 | 1130 | | |
1124 | 1131 | | |
1125 | 1132 | | |
| |||
1155 | 1162 | | |
1156 | 1163 | | |
1157 | 1164 | | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1158 | 1173 | | |
1159 | 1174 | | |
1160 | 1175 | | |
| |||
1172 | 1187 | | |
1173 | 1188 | | |
1174 | 1189 | | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1179 | 1199 | | |
1180 | | - | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
1181 | 1209 | | |
1182 | 1210 | | |
1183 | 1211 | | |
| |||
0 commit comments