After closing web socket connection not all OkHttp's threads are terminated
See original GitHub issueHi,
I just wrote simple app like this:
final OkHttpClient httpClient = new OkHttpClient();
final WebSocket webSocket = httpClient.newWebSocket(new Request.Builder().url("ws://demos.kaazing.com/echo").build(), new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
System.out.println("STARTED!");
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
System.out.println("CLOSED!");
}
});
Thread.sleep(1000);
webSocket.close(1000, "Closed.");
Thread.sleep(1000);
Thread.getAllStackTraces().keySet().stream()
.filter(Thread::isAlive)
.forEach(System.out::println);
System output:
STARTED!
CLOSED!
Thread[Signal Dispatcher,9,system]
Thread[Okio Watchdog,5,main]
Thread[OkHttp ConnectionPool,5,main]
Thread[main,5,main]
Thread[Finalizer,8,system]
Thread[OkHttp Dispatcher,5,main]
Thread[Reference Handler,10,system]
Thread[Monitor Ctrl-Break,5,main]
It looks like the OkHttp Dispatcher is waiting for something.
After calling:
httpClient.dispatcher().executorService().shutdown();
All OkHttp’s threads are terminated and java process is finally down.
Is it expected behaviour?
I don’t have similar problems when I call http request, the problem occurs only with web sockets.
Best, Adrian
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Websocket connection wasn't closed after the app killed
To solve this issue I manually close socket and remove all idle connections: fun clear() { webSocket?.close(1001, "Android: User exited the ...
Read more >Concurrency - OkHttp - Square Open Source
Its job is to maintain a reference to all open connections. When an HTTP request is started, OkHttp will attempt to reuse an...
Read more >Unidirectional Server-Client Communication using SSE in ...
After closing the connection by either of the client and server, the connection is terminated from both ends. This is suitable for use-cases ......
Read more >Replicator pull continous stop after network error in ...
I/CouchbaseLite/NETWORK: WebSocket CLOSED … ... The replicator does not start again when re-establishing a connection.
Read more >Heroku Error Codes
This error is thrown when a process in your web dyno accepts a connection but then closes the socket without writing anything to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m calling
on all OkHttpClient instances, yet the application does not exit until after the
Okio Watchdog
thread is done, around 30 seconds after the shutdown has been initiated.Is there a way to manually shutdown that thread too?
Alguna solución?