mirror of https://github.com/grpc/grpc-java.git
Fix AsyncServletOutputStreamWriterConcurrencyTest flakiness (#9948)
The commit792946132c (diff-cc7b2eb82d208e027f432435bcd324a46713c31096352f437417b770752f92abR197)
makes it possible that the sleep can naturally wake up while `writeState` gets changes at the same time, causing a data race in the value of `parkingThread` between792946132c/servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java (L199)
and792946132c/servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java (L218)
, in extreme scenario such as the CPU is stressed. Fixes #9917
This commit is contained in:
parent
687340bbbe
commit
85e656c0dc
|
@ -194,7 +194,9 @@ final class AsyncServletOutputStreamWriter {
|
|||
// being set to false by runOrBuffer() concurrently.
|
||||
while (writeState.get().readyAndDrained) {
|
||||
parkingThread = Thread.currentThread();
|
||||
LockSupport.parkNanos(Duration.ofMinutes(1).toNanos()); // should return immediately
|
||||
// Try to sleep for an extremely long time to avoid writeState being changed at exactly
|
||||
// the time when sleep time expires (in extreme scenario, such as #9917).
|
||||
LockSupport.parkNanos(Duration.ofHours(1).toNanos()); // should return immediately
|
||||
}
|
||||
parkingThread = null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue