|
20 | 20 | package org.apache.iotdb.rpc; |
21 | 21 |
|
22 | 22 | import org.apache.thrift.TConfiguration; |
| 23 | +import org.apache.thrift.transport.TSocket; |
23 | 24 | import org.apache.thrift.transport.TTransport; |
24 | 25 | import org.apache.thrift.transport.TTransportException; |
25 | 26 | import org.apache.thrift.transport.TTransportFactory; |
26 | 27 | import org.apache.thrift.transport.layered.TFramedTransport; |
27 | 28 |
|
| 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 | + |
28 | 37 | // https://github.com/apache/thrift/blob/master/doc/specs/thrift-rpc.md |
29 | 38 | public class TElasticFramedTransport extends TTransport { |
30 | 39 |
|
@@ -113,8 +122,52 @@ public int read(byte[] buf, int off, int len) throws TTransportException { |
113 | 122 | return got; |
114 | 123 | } |
115 | 124 |
|
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 | + } |
118 | 171 | return readBuffer.read(buf, off, len); |
119 | 172 | } |
120 | 173 |
|
|
0 commit comments