Skip to content

Commit 2357514

Browse files
committed
[java] close the HttpClient if possible
1 parent aaf3d0b commit 2357514

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,28 @@ public void close() {
511511
if (this.client == null) {
512512
return;
513513
}
514-
this.client = null;
514+
515515
for (WebSocket websocket : websockets) {
516516
try {
517517
websocket.close();
518518
} catch (Exception e) {
519519
LOG.log(Level.WARNING, "failed to close the websocket: " + websocket, e);
520520
}
521521
}
522-
executorService.shutdownNow();
522+
523+
if (this.client instanceof AutoCloseable) {
524+
AutoCloseable closeable = (AutoCloseable) this.client;
525+
executorService.submit(
526+
() -> {
527+
try {
528+
closeable.close();
529+
} catch (Exception e) {
530+
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
531+
}
532+
});
533+
}
534+
this.client = null;
535+
executorService.shutdown();
523536
}
524537

525538
@AutoService(HttpClient.Factory.class)

0 commit comments

Comments
 (0)