Skip to content

Commit 0544a73

Browse files
committed
8255227: java/net/httpclient/FlowAdapterPublisherTest.java intermittently failing with TestServer: start exception: java.io.IOException: Invalid preface
Reviewed-by: chegar
1 parent 48bb996 commit 0544a73

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/java.net.http/share/classes/jdk/internal/net/http/Stream.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -926,7 +926,6 @@ else if (item == COMPLETED) {
926926
// handle bytes to send downstream
927927
while (item.hasRemaining() && state == 0) {
928928
if (debug.on()) debug.log("trySend: %d", item.remaining());
929-
assert !endStreamSent : "internal error, send data after END_STREAM flag";
930929
DataFrame df = getDataFrame(item);
931930
if (df == null) {
932931
if (debug.on())
@@ -947,9 +946,12 @@ else if (item == COMPLETED) {
947946
connection.resetStream(streamid, ResetFrame.PROTOCOL_ERROR);
948947
throw new IOException(msg);
949948
} else if (remainingContentLength == 0) {
949+
assert !endStreamSent : "internal error, send data after END_STREAM flag";
950950
df.setFlag(DataFrame.END_STREAM);
951951
endStreamSent = true;
952952
}
953+
} else {
954+
assert !endStreamSent : "internal error, send data after END_STREAM flag";
953955
}
954956
if ((state = streamState) != 0) {
955957
if (debug.on()) debug.log("trySend: cancelled: %s", String.valueOf(t));

test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,6 +47,7 @@
4747
import jdk.internal.net.http.hpack.Encoder;
4848
import sun.net.www.http.ChunkedInputStream;
4949
import sun.net.www.http.HttpClient;
50+
import static java.nio.charset.StandardCharsets.ISO_8859_1;
5051
import static java.nio.charset.StandardCharsets.UTF_8;
5152
import static jdk.internal.net.http.frame.SettingsFrame.HEADER_TABLE_SIZE;
5253

@@ -304,9 +305,11 @@ void close(int error) {
304305
private void readPreface() throws IOException {
305306
int len = clientPreface.length;
306307
byte[] bytes = new byte[len];
307-
is.readNBytes(bytes, 0, len);
308+
int n = is.readNBytes(bytes, 0, len);
308309
if (Arrays.compare(clientPreface, bytes) != 0) {
309-
throw new IOException("Invalid preface: " + new String(bytes, 0, len));
310+
System.err.printf("Invalid preface: read %d/%d bytes%n", n, len);
311+
throw new IOException("Invalid preface: " +
312+
new String(bytes, 0, len, ISO_8859_1));
310313
}
311314
}
312315

0 commit comments

Comments
 (0)