Commit fd48842
committed
servlet: fix UndertowTransportTest flakiness by eliminating container thread parking deadlocks (grpc#12778)
Fixes a long-standing flakiness bug in UndertowTransportTest.basicStream
where the container worker thread would park for up to 1 minute in
AsyncServletOutputStreamWriter.assureReadyAndDrainedTurnsFalse(), causing
the test listener poll to time out after 10 seconds and fail with
AssertionError: message expected.
Root Cause:
AsyncServletOutputStreamWriter previously assumed that readyAndDrained could
only be true while onWritePossible() was actively executing and that any call
to runOrBuffer() would return readyAndDrained back to false. However, when written
payloads fit inside the servlet output buffer, outputStream.isReady() remains
true after runOrBuffer() finishes, so runOrBuffer() exits leaving
readyAndDrained == true.
When Undertow subsequently dispatched WriteListener.onWritePossible() after async
I/O write completion, onWritePossible() saw readyAndDrained == true and invoked
assureReadyAndDrainedTurnsFalse(), parking the Undertow container thread via
LockSupport.parkNanos(1 min). Because the application thread had already returned,
no thread was running runOrBuffer() to clear readyAndDrained, leaving Undertow
blocked for 60 seconds and causing the test timeout.
Fix:
1. Removed assureReadyAndDrainedTurnsFalse() and LockSupport parking logic.
A state of readyAndDrained == true with an empty writeChain and isReady() == true
is a valid quiescent state; onWritePossible() verifies the queue is empty and
exits cleanly without parking.
2. Safe state updates in runOrBuffer() when outputStream is not ready.
Fixes grpc#127781 parent bc01994 commit fd48842
1 file changed
Lines changed: 1 addition & 22 deletions
Lines changed: 1 addition & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
| |||
173 | 169 | | |
174 | 170 | | |
175 | 171 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | 172 | | |
180 | 173 | | |
181 | 174 | | |
| |||
198 | 191 | | |
199 | 192 | | |
200 | 193 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | 194 | | |
213 | 195 | | |
214 | 196 | | |
| |||
223 | 205 | | |
224 | 206 | | |
225 | 207 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 208 | + | |
230 | 209 | | |
231 | 210 | | |
232 | 211 | | |
| |||
0 commit comments