Skip to content

Commit

Permalink
Merge pull request #5707 from square/jwilson.0106.close_without_connect_
Browse files Browse the repository at this point in the history
Fix a regression closing WebSockets before connect
  • Loading branch information
swankjesse committed Jan 7, 2020
2 parents 1533935 + 43996f3 commit 1e02ecd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion okhttp/src/main/java/okhttp3/internal/ws/RealWebSocket.kt
Expand Up @@ -395,7 +395,10 @@ class RealWebSocket(
private fun runWriter() {
this.assertThreadHoldsLock()

taskQueue.schedule(writerTask!!)
val writerTask = writerTask
if (writerTask != null) {
taskQueue.schedule(writerTask)
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions okhttp/src/test/java/okhttp3/internal/ws/WebSocketHttpTest.java
Expand Up @@ -762,6 +762,16 @@ public final class WebSocketHttpTest {
assertThat(webServer.takeRequest().getSequenceNumber()).isEqualTo(1);
}

/** https://github.com/square/okhttp/issues/5705 */
@Test public void closeWithoutSuccessfulConnect() {
Request request = new Request.Builder()
.url(webServer.url("/"))
.build();
WebSocket webSocket = client.newWebSocket(request, clientListener);
webSocket.send("hello");
webSocket.close(1000, null);
}

private MockResponse upgradeResponse(RecordedRequest request) {
String key = request.getHeader("Sec-WebSocket-Key");
return new MockResponse()
Expand Down

0 comments on commit 1e02ecd

Please sign in to comment.