author | dfuchs |
Mon, 23 Apr 2018 15:45:40 +0100 | |
branch | http-client-branch |
changeset 56474 | fe2bf7b369b8 |
parent 56451 | 9585061fdb04 |
child 56507 | 2294c51eae30 |
permissions | -rw-r--r-- |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
1 |
/* |
49765 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
4 |
* |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
8 |
* |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
14 |
* |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
18 |
* |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
22 |
*/ |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
23 |
|
49765 | 24 |
import java.net.InetAddress; |
25 |
import java.net.InetSocketAddress; |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
26 |
import java.net.ServerSocket; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
27 |
import java.net.URI; |
49765 | 28 |
import java.net.http.HttpClient; |
29 |
import java.net.http.HttpRequest; |
|
30 |
import java.net.http.HttpResponse; |
|
31 |
import java.net.http.HttpResponse.BodyHandlers; |
|
32 |
import java.net.http.HttpTimeoutException; |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
33 |
import java.time.Duration; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
34 |
import java.util.concurrent.CompletableFuture; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
35 |
import java.util.concurrent.ExecutorService; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
36 |
import java.util.concurrent.Executors; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
37 |
import java.util.concurrent.LinkedBlockingQueue; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
38 |
import static java.lang.System.out; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
39 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
40 |
/** |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
41 |
* @test |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
42 |
* @bug 8178147 |
49765 | 43 |
* @modules java.net.http/jdk.internal.net.http.common |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
44 |
* @summary Ensures that small timeouts do not cause hangs due to race conditions |
49765 | 45 |
* @run main/othervm -Djdk.internal.httpclient.debug=true SmallTimeout |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
46 |
*/ |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
47 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
48 |
// To enable logging use. Not enabled by default as it changes the dynamics |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
49 |
// of the test. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
50 |
// @run main/othervm -Djdk.httpclient.HttpClient.log=all,frames:all SmallTimeout |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
51 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
52 |
public class SmallTimeout { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
53 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
54 |
static int[] TIMEOUTS = {2, 1, 3, 2, 100, 1}; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
55 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
56 |
// A queue for placing timed out requests so that their order can be checked. |
48083 | 57 |
static LinkedBlockingQueue<HttpResult> queue = new LinkedBlockingQueue<>(); |
58 |
||
59 |
static final class HttpResult { |
|
60 |
final HttpRequest request; |
|
61 |
final Throwable failed; |
|
62 |
HttpResult(HttpRequest request, Throwable failed) { |
|
63 |
this.request = request; |
|
64 |
this.failed = failed; |
|
65 |
} |
|
66 |
||
67 |
static HttpResult of(HttpRequest request) { |
|
68 |
return new HttpResult(request, null); |
|
69 |
} |
|
70 |
||
71 |
static HttpResult of(HttpRequest request, Throwable t) { |
|
72 |
return new HttpResult(request, t); |
|
73 |
} |
|
74 |
||
75 |
} |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
76 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
77 |
static volatile boolean error; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
78 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
79 |
public static void main(String[] args) throws Exception { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
80 |
HttpClient client = HttpClient.newHttpClient(); |
49765 | 81 |
ReferenceTracker.INSTANCE.track(client); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
82 |
|
49765 | 83 |
Throwable failed = null; |
84 |
try (ServerSocket ss = new ServerSocket()) { |
|
85 |
ss.setReuseAddress(false); |
|
86 |
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
87 |
int port = ss.getLocalPort(); |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
88 |
URI u = new URI("http://localhost:" + port + "/"); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
89 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
90 |
HttpRequest[] requests = new HttpRequest[TIMEOUTS.length]; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
91 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
92 |
out.println("--- TESTING Async"); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
93 |
for (int i = 0; i < TIMEOUTS.length; i++) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
94 |
final int n = i; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
95 |
URI uri = new URI(u.toString() + "/r" + n); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
96 |
requests[i] = HttpRequest.newBuilder(uri) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
97 |
.timeout(Duration.ofMillis(TIMEOUTS[i])) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
98 |
.GET() |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
99 |
.build(); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
100 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
101 |
final HttpRequest req = requests[i]; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
102 |
CompletableFuture<HttpResponse<Object>> response = client |
49765 | 103 |
.sendAsync(req, BodyHandlers.replacing(null)) |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
104 |
.whenComplete((HttpResponse<Object> r, Throwable t) -> { |
48083 | 105 |
Throwable cause = null; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
106 |
if (r != null) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
107 |
out.println("Unexpected response for r" + n + ": " + r); |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
108 |
cause = new RuntimeException("Unexpected response for r" + n); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
109 |
error = true; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
110 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
111 |
if (t != null) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
112 |
if (!(t.getCause() instanceof HttpTimeoutException)) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
113 |
out.println("Wrong exception type for r" + n + ":" + t.toString()); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
114 |
Throwable c = t.getCause() == null ? t : t.getCause(); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
115 |
c.printStackTrace(); |
48083 | 116 |
cause = c; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
117 |
error = true; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
118 |
} else { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
119 |
out.println("Caught expected timeout for r" + n +": " + t.getCause()); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
120 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
121 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
122 |
if (t == null && r == null) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
123 |
out.println("Both response and throwable are null for r" + n + "!"); |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
124 |
cause = new RuntimeException("Both response and throwable are null for r" |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
125 |
+ n + "!"); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
126 |
error = true; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
127 |
} |
48083 | 128 |
queue.add(HttpResult.of(req,cause)); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
129 |
}); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
130 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
131 |
System.out.println("All requests submitted. Waiting ..."); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
132 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
133 |
checkReturn(requests); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
134 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
135 |
if (error) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
136 |
throw new RuntimeException("Failed. Check output"); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
137 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
138 |
// Repeat blocking in separate threads. Use queue to wait. |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
139 |
out.println("--- TESTING Sync"); |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
140 |
System.err.println("================= TESTING Sync ====================="); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
141 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
142 |
// For running blocking response tasks |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
143 |
ExecutorService executor = Executors.newCachedThreadPool(); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
144 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
145 |
for (int i = 0; i < TIMEOUTS.length; i++) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
146 |
final int n = i; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
147 |
URI uri = new URI(u.toString()+"/sync/r" + n); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
148 |
requests[i] = HttpRequest.newBuilder(uri) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
149 |
.timeout(Duration.ofMillis(TIMEOUTS[i])) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
150 |
.GET() |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
151 |
.build(); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
152 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
153 |
final HttpRequest req = requests[i]; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
154 |
executor.execute(() -> { |
48083 | 155 |
Throwable cause = null; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
156 |
try { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
157 |
HttpResponse<?> r = client.send(req, BodyHandlers.replacing(null)); |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
158 |
out.println("Unexpected success for r" + n +": " + r); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
159 |
} catch (HttpTimeoutException e) { |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
160 |
out.println("Caught expected timeout for r" + n +": " + e); |
48083 | 161 |
} catch (Throwable ee) { |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
162 |
Throwable c = ee.getCause() == null ? ee : ee.getCause(); |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
56451
diff
changeset
|
163 |
out.println("Unexpected exception for r" + n + ": " + c); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
164 |
c.printStackTrace(); |
48083 | 165 |
cause = c; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
166 |
error = true; |
48083 | 167 |
} finally { |
168 |
queue.offer(HttpResult.of(req, cause)); |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
169 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
170 |
}); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
171 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
172 |
System.out.println("All requests submitted. Waiting ..."); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
173 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
174 |
checkReturn(requests); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
175 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
176 |
executor.shutdownNow(); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
177 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
178 |
if (error) |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
179 |
throw new RuntimeException("Failed. Check output"); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
180 |
|
49765 | 181 |
} catch (Throwable t) { |
182 |
failed = t; |
|
183 |
throw t; |
|
184 |
} finally { |
|
185 |
try { |
|
186 |
Thread.sleep(100); |
|
187 |
} catch (InterruptedException t) { |
|
188 |
// ignore; |
|
189 |
} |
|
190 |
AssertionError trackFailed = ReferenceTracker.INSTANCE.check(500); |
|
191 |
if (trackFailed != null) { |
|
192 |
if (failed != null) { |
|
193 |
failed.addSuppressed(trackFailed); |
|
194 |
if (failed instanceof Exception) throw (Exception) failed; |
|
195 |
if (failed instanceof Error) throw (Exception) failed; |
|
196 |
} |
|
197 |
throw trackFailed; |
|
198 |
} |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
199 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
200 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
201 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
202 |
static void checkReturn(HttpRequest[] requests) throws InterruptedException { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
203 |
// wait for exceptions and check order |
48083 | 204 |
boolean ok = true; |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
205 |
for (int j = 0; j < TIMEOUTS.length; j++) { |
48083 | 206 |
HttpResult res = queue.take(); |
207 |
HttpRequest req = res.request; |
|
208 |
out.println("Got request from queue " + req + ", order: " + getRequest(req, requests) |
|
209 |
+ (res.failed == null ? "" : " failed: " + res.failed)); |
|
210 |
ok = ok && res.failed == null; |
|
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
211 |
} |
48083 | 212 |
out.println("Return " + (ok ? "ok" : "nok")); |
44639
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
213 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
214 |
|
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
215 |
/** Returns the index of the request in the array. */ |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
216 |
static String getRequest(HttpRequest req, HttpRequest[] requests) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
217 |
for (int i=0; i<requests.length; i++) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
218 |
if (req == requests[i]) { |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
219 |
return "r" + i; |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
220 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
221 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
222 |
throw new AssertionError("Unknown request: " + req); |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
223 |
} |
5c2838d882a5
8178147: Race conditions in timeout handling code in http/2 incubator client
dfuchs
parents:
diff
changeset
|
224 |
} |