@@ -211,7 +211,31 @@ public void onError(java.net.http.WebSocket webSocket, Throwable error) {
211211 }
212212 });
213213
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+ }
215239
216240 this .websocket =
217241 new WebSocket () {
@@ -340,7 +364,31 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
340364 // - not run into https://bugs.openjdk.org/browse/JDK-8304701
341365 for (int i = 0 ; i < 100 ; i ++) {
342366 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+ }
344392
345393 switch (response .statusCode ()) {
346394 case 301 :
@@ -376,8 +424,6 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
376424 }
377425
378426 throw new ProtocolException ("Too many redirects: 101" );
379- } catch (HttpTimeoutException e ) {
380- throw new TimeoutException (e );
381427 } catch (IOException e ) {
382428 throw new UncheckedIOException (e );
383429 } catch (InterruptedException e ) {
0 commit comments