Commit 497bc87
authored
ssh/proxy: improve cancellation and resource cleanup (#3965)
## Changes
<!-- Brief summary of your changes that is easy to understand -->
There are edge cases where the proxy connection could hang indefinitely
during shutdown if the sending or receiving loops were blocked on I/O
(e.g. reading from stdin or the websocket).
- Introduce a dedicated cleanup goroutine in `start` that waits for
context cancellation and explicitly closes both the websocket connection
and the source. This ensures that blocked `Read` calls return
immediately with an error, allowing the `errgroup` to finish.
- Ensure that sending and receiving loops always return a non-nil error
to trigger `errgroup` cancellation for the other loop.
- Update `RunClientProxy` and `proxyConnection.start` to accept
`io.ReadCloser` instead of `io.Reader`, allowing the proxy to close the
input source.
## Tests
Existing tests with additional `-count` and `-race` flags.
<!-- If your PR needs to be included in the release notes for next
release,
add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->1 parent d689a0d commit 497bc87
File tree
4 files changed
+52
-8
lines changed- experimental/ssh/internal/proxy
4 files changed
+52
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| |||
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| |||
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
| 113 | + | |
105 | 114 | | |
106 | 115 | | |
107 | 116 | | |
108 | | - | |
| 117 | + | |
109 | 118 | | |
110 | 119 | | |
111 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
112 | 128 | | |
113 | 129 | | |
114 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
115 | 138 | | |
116 | 139 | | |
117 | 140 | | |
| |||
121 | 144 | | |
122 | 145 | | |
123 | 146 | | |
| 147 | + | |
124 | 148 | | |
125 | 149 | | |
126 | 150 | | |
| |||
130 | 154 | | |
131 | 155 | | |
132 | 156 | | |
| 157 | + | |
133 | 158 | | |
134 | 159 | | |
135 | 160 | | |
| |||
236 | 261 | | |
237 | 262 | | |
238 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
239 | 272 | | |
240 | 273 | | |
241 | 274 | | |
| |||
283 | 316 | | |
284 | 317 | | |
285 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
286 | 326 | | |
287 | 327 | | |
288 | 328 | | |
| |||
303 | 343 | | |
304 | 344 | | |
305 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
306 | 350 | | |
307 | 351 | | |
308 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
0 commit comments