Skip to content

Commit 6f029dd

Browse files
authored
Fix MockWebServer websockets to be thread safe. (square#3567)
Closing the sink while another thread is writing the sink is a potential source for races. Closes: square#3138
1 parent 9f8200d commit 6f029dd

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ public void processConnection() throws Exception {
465465
+ " didn't make a request");
466466
}
467467

468-
source.close();
469-
sink.close();
470468
socket.close();
471469
openClientSockets.remove(socket);
472470
}
@@ -681,7 +679,6 @@ private void handleWebSocketUpgrade(Socket socket, BufferedSource source, Buffer
681679
} catch (IOException e) {
682680
webSocket.failWebSocket(e, null);
683681
} finally {
684-
closeQuietly(sink);
685682
closeQuietly(source);
686683
}
687684
}

okhttp-tests/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public final class WebSocketHttpTest {
322322
assertNull(chain.request().body());
323323
Response response = chain.proceed(chain.request());
324324
assertEquals("Upgrade", response.header("Connection"));
325-
assertTrue("", response.body().source().exhausted());
325+
assertTrue(response.body().source().exhausted());
326326
interceptedCount.incrementAndGet();
327327
return response;
328328
}

0 commit comments

Comments
 (0)