Commit 46f3080
authored
servlet: fix TomcatTransportTest detects write when not ready (#12732)
Fixes #12723
### What was happening
In `AsyncServletOutputStreamWriter#runOrBuffer`, the application thread
relies on the cached `readyAndDrained `state to determine if it can
write directly to the `ServletOutputStream`.
In highly concurrent scenarios (observed in `TomcatTransportTest`), this
cached state can become stale. The servlet container may have already
transitioned to a 'not ready' state, but the corresponding callback has
not yet updated gRPC's internal state. When the application thread
attempts to write based on the stale `true `value, the container throws
an `IllegalStateException`.
### The Fix
This PR updates the primary execution path in `runOrBuffer` to
explicitly evaluate `isReady.getAsBoolean()` alongside the cached state.
If the cached state is true but the container is actually not ready, the
thread gracefully drops into the `else` block, buffers the action into
the `writeChain`, and attempts to update `readyAndDrained` to `false`.1 parent 073fd5e commit 46f3080
1 file changed
Lines changed: 34 additions & 18 deletions
Lines changed: 34 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
| |||
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
220 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
221 | 240 | | |
222 | 241 | | |
223 | 242 | | |
224 | 243 | | |
225 | 244 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
231 | 259 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | 260 | | |
245 | 261 | | |
246 | 262 | | |
| |||
0 commit comments