Skip to content

Commit 752313e

Browse files
jt2594838HTHou
andauthored
Avoid connection reset error log printed (#16797) (#16802)
Co-authored-by: Haonan <[email protected]>
1 parent 1d267aa commit 752313e

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TElasticFramedTransport.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@
2020
package org.apache.iotdb.rpc;
2121

2222
import org.apache.thrift.TConfiguration;
23+
import org.apache.thrift.transport.TSocket;
2324
import org.apache.thrift.transport.TTransport;
2425
import org.apache.thrift.transport.TTransportException;
2526
import org.apache.thrift.transport.TTransportFactory;
2627
import org.apache.thrift.transport.layered.TFramedTransport;
2728

29+
import javax.net.ssl.SSLException;
30+
import javax.net.ssl.SSLHandshakeException;
31+
32+
import java.io.EOFException;
33+
import java.net.SocketAddress;
34+
import java.net.SocketException;
35+
import java.net.SocketTimeoutException;
36+
2837
// https://github.com/apache/thrift/blob/master/doc/specs/thrift-rpc.md
2938
public class TElasticFramedTransport extends TTransport {
3039

@@ -113,8 +122,52 @@ public int read(byte[] buf, int off, int len) throws TTransportException {
113122
return got;
114123
}
115124

116-
// Read another frame of data
117-
readFrame();
125+
try {
126+
// Read another frame of data
127+
readFrame();
128+
} catch (TTransportException e) {
129+
// Adding this workaround to avoid the Connection reset error log printed.
130+
if (e.getCause() instanceof SocketException && e.getMessage().contains("Connection reset")) {
131+
throw new TTransportException(TTransportException.END_OF_FILE, e.getCause());
132+
}
133+
// There is a bug fixed in Thrift 0.15. Some unnecessary error logs may be printed.
134+
// See https://issues.apache.org/jira/browse/THRIFT-5411 and
135+
// https://github.com/apache/thrift/commit/be20ad7e08fab200391e3eab41acde9da2a4fd07
136+
// Adding this workaround to avoid the problem.
137+
if (e.getCause() instanceof SocketTimeoutException) {
138+
throw new TTransportException(TTransportException.TIMED_OUT, e.getCause());
139+
}
140+
if (e.getCause() instanceof SSLHandshakeException) {
141+
// There is an unsolved JDK bug https://bugs.openjdk.org/browse/JDK-8221218.
142+
// Adding this workaround to avoid the error log printed.
143+
if (e.getMessage()
144+
.contains("Insufficient buffer remaining for AEAD cipher fragment (2).")) {
145+
throw new TTransportException(TTransportException.END_OF_FILE, e.getCause());
146+
}
147+
// When client with SSL shutdown due to time out. Some unnecessary error logs may be
148+
// printed.
149+
// Adding this workaround to avoid the problem.
150+
if (e.getCause().getCause() != null && e.getCause().getCause() instanceof EOFException) {
151+
throw new TTransportException(TTransportException.END_OF_FILE, e.getCause());
152+
}
153+
}
154+
155+
if (e.getCause() instanceof SSLException
156+
&& e.getMessage().contains("Unsupported or unrecognized SSL message")) {
157+
SocketAddress remoteAddress = null;
158+
if (underlying instanceof TSocket) {
159+
remoteAddress = ((TSocket) underlying).getSocket().getRemoteSocketAddress();
160+
}
161+
throw new TTransportException(
162+
TTransportException.CORRUPTED_DATA,
163+
String.format(
164+
"You may be sending non-SSL requests"
165+
+ "%s to the SSL-enabled Thrift-RPC port, please confirm that you are "
166+
+ "using the right configuration",
167+
remoteAddress == null ? "" : " from " + remoteAddress));
168+
}
169+
throw e;
170+
}
118171
return readBuffer.read(buf, off, len);
119172
}
120173

0 commit comments

Comments
 (0)