1616
1717package io .grpc .servlet ;
1818
19- import static com .google .common .base .Preconditions .checkState ;
2019import static io .grpc .servlet .ServletServerStream .toHexString ;
2120import static java .util .logging .Level .FINE ;
2221import static java .util .logging .Level .FINEST ;
2322
2423import com .google .common .annotations .VisibleForTesting ;
25- import com .google .errorprone .annotations .CheckReturnValue ;
2624import io .grpc .InternalLogId ;
2725import io .grpc .servlet .ServletServerStream .ServletTransportState ;
2826import java .io .IOException ;
@@ -215,6 +213,7 @@ private boolean assureWritingStateTurnsStateOtherThanWriting() {
215213 while (writeState .get ().state == WriteState .WRITING ) {
216214 LockSupport .parkNanos (TimeUnit .MINUTES .toNanos (1 ));
217215 if (Thread .interrupted ()) {
216+ Thread .currentThread ().interrupt ();
218217 log .fine ("Thread interrupted while parked" );
219218 return false ;
220219 }
@@ -244,7 +243,7 @@ private void runOrBuffer(ActionItem actionItem) throws IOException {
244243 if (itemToWrite != null ) {
245244 itemToWrite .run ();
246245 if (itemToWrite == completeAction ) {
247- writeState .set (WriteState . DEFAULT );
246+ writeState .set (new WriteState ( WriteState . NOT_READY_OR_NOT_DRAINED ) );
248247 LockSupport .unpark (parkingThread );
249248 successfulExited = true ;
250249 return ;
@@ -258,7 +257,8 @@ private void runOrBuffer(ActionItem actionItem) throws IOException {
258257 }
259258 WriteState latestState = writeState .get ();
260259 if (latestState .state == WriteState .WRITING ) {
261- if (writeState .compareAndSet (latestState , new WriteState (WriteState .READY_AND_DRAINED ))) {
260+ if (writeState .compareAndSet (
261+ latestState , new WriteState (WriteState .READY_AND_DRAINED ))) {
262262 LockSupport .unpark (parkingThread );
263263 successfulExited = true ;
264264 return ;
@@ -271,7 +271,8 @@ private void runOrBuffer(ActionItem actionItem) throws IOException {
271271 } else {
272272 WriteState latestState = writeState .get ();
273273 if (latestState .state == WriteState .WRITING ) {
274- if (writeState .compareAndSet (latestState , WriteState .DEFAULT )) {
274+ if (writeState .compareAndSet (
275+ latestState , new WriteState (WriteState .NOT_READY_OR_NOT_DRAINED ))) {
275276 LockSupport .unpark (parkingThread );
276277 log .finest ("the servlet output stream becomes not ready" );
277278 successfulExited = true ;
@@ -287,7 +288,7 @@ private void runOrBuffer(ActionItem actionItem) throws IOException {
287288 }
288289 } finally {
289290 if (!successfulExited ) {
290- writeState .set (WriteState . DEFAULT );
291+ writeState .set (new WriteState ( WriteState . NOT_READY_OR_NOT_DRAINED ) );
291292 LockSupport .unpark (parkingThread );
292293 }
293294 }
0 commit comments