@@ -211,7 +211,31 @@ public void onError(java.net.http.WebSocket webSocket, Throwable error) {
211
211
}
212
212
});
213
213
214
- java .net .http .WebSocket underlyingSocket = webSocketCompletableFuture .join ();
214
+ java .net .http .WebSocket underlyingSocket ;
215
+
216
+ try {
217
+ underlyingSocket = webSocketCompletableFuture .get (readTimeout .toMillis (), TimeUnit .MILLISECONDS );
218
+ } catch (CancellationException e ) {
219
+ throw new WebDriverException (e .getMessage (), e );
220
+ } catch (ExecutionException e ) {
221
+ Throwable cause = e .getCause ();
222
+
223
+ if (cause instanceof HttpTimeoutException ) {
224
+ throw new TimeoutException (cause );
225
+ } else if (cause instanceof IOException ) {
226
+ throw new UncheckedIOException ((IOException ) cause );
227
+ } else if (cause instanceof RuntimeException ) {
228
+ throw (RuntimeException ) cause ;
229
+ }
230
+
231
+ throw new WebDriverException ((cause != null ) ? cause : e );
232
+ } catch (InterruptedException e ) {
233
+ Thread .currentThread ().interrupt ();
234
+ throw new RuntimeException (e );
235
+ } catch (java .util .concurrent .TimeoutException e ) {
236
+ webSocketCompletableFuture .cancel (true );
237
+ throw new TimeoutException (e );
238
+ }
215
239
216
240
this .websocket =
217
241
new WebSocket () {
@@ -340,7 +364,31 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
340
364
// - not run into https://bugs.openjdk.org/browse/JDK-8304701
341
365
for (int i = 0 ; i < 100 ; i ++) {
342
366
java .net .http .HttpRequest request = messages .createRequest (req , rawUri );
343
- java .net .http .HttpResponse <byte []> response = client .send (request , byteHandler );
367
+ java .net .http .HttpResponse <byte []> response ;
368
+
369
+ // use sendAsync to not run into https://bugs.openjdk.org/browse/JDK-8258397
370
+ CompletableFuture <java .net .http .HttpResponse <byte []>> future = client .sendAsync (request , byteHandler );
371
+
372
+ try {
373
+ response = future .get (readTimeout .toMillis (), TimeUnit .MILLISECONDS );
374
+ } catch (CancellationException e ) {
375
+ throw new WebDriverException (e .getMessage (), e );
376
+ } catch (ExecutionException e ) {
377
+ Throwable cause = e .getCause ();
378
+
379
+ if (cause instanceof HttpTimeoutException ) {
380
+ throw new TimeoutException (cause );
381
+ } else if (cause instanceof IOException ) {
382
+ throw (IOException ) cause ;
383
+ } else if (cause instanceof RuntimeException ) {
384
+ throw (RuntimeException ) cause ;
385
+ }
386
+
387
+ throw new WebDriverException ((cause != null ) ? cause : e );
388
+ } catch (java .util .concurrent .TimeoutException e ) {
389
+ future .cancel (true );
390
+ throw new TimeoutException (e );
391
+ }
344
392
345
393
switch (response .statusCode ()) {
346
394
case 301 :
@@ -376,8 +424,6 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
376
424
}
377
425
378
426
throw new ProtocolException ("Too many redirects: 101" );
379
- } catch (HttpTimeoutException e ) {
380
- throw new TimeoutException (e );
381
427
} catch (IOException e ) {
382
428
throw new UncheckedIOException (e );
383
429
} catch (InterruptedException e ) {
0 commit comments