mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-2268:Modify TSaslTransport to ignore TCP health checks from loadbalancers
Client: java Patch: Thiruvel Thirumoolan Adds a TSaslTransportException to be able to catch and ignore invalid Sasl headers
This commit is contained in:
parent
9f154150b7
commit
607355e1de
@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.TProcessor;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.transport.TSaslTransportException;
|
||||
import org.apache.thrift.transport.TServerTransport;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
@ -226,6 +227,8 @@ public class TThreadPoolServer extends TServer {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (TSaslTransportException ttx) {
|
||||
// Something thats not SASL was in the stream, continue silently
|
||||
} catch (TTransportException ttx) {
|
||||
// Assume the client died and continue silently
|
||||
} catch (TException tx) {
|
||||
|
@ -240,6 +240,13 @@ abstract class TSaslTransport extends TTransport {
|
||||
*/
|
||||
@Override
|
||||
public void open() throws TTransportException {
|
||||
/*
|
||||
* readSaslHeader is used to tag whether the SASL header has been read properly.
|
||||
* If there is a problem in reading the header, there might not be any
|
||||
* data in the stream, possibly a TCP health check from load balancer.
|
||||
*/
|
||||
boolean readSaslHeader = false;
|
||||
|
||||
LOGGER.debug("opening transport {}", this);
|
||||
if (sasl != null && sasl.isComplete())
|
||||
throw new TTransportException("SASL transport already open");
|
||||
@ -251,6 +258,7 @@ abstract class TSaslTransport extends TTransport {
|
||||
// Negotiate a SASL mechanism. The client also sends its
|
||||
// initial response, or an empty one.
|
||||
handleSaslStartMessage();
|
||||
readSaslHeader = true;
|
||||
LOGGER.debug("{}: Start message handled", getRole());
|
||||
|
||||
SaslResponse message = null;
|
||||
@ -298,6 +306,17 @@ abstract class TSaslTransport extends TTransport {
|
||||
} finally {
|
||||
underlyingTransport.close();
|
||||
}
|
||||
} catch (TTransportException e) {
|
||||
/*
|
||||
* If there is no-data or no-sasl header in the stream, throw a different
|
||||
* type of exception so we can handle this scenario differently.
|
||||
*/
|
||||
if (!readSaslHeader && e.getType() == TTransportException.END_OF_FILE) {
|
||||
underlyingTransport.close();
|
||||
LOGGER.debug("No data or no sasl data in the stream");
|
||||
throw new TSaslTransportException("No data or no sasl data in the stream");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
String qop = (String) sasl.getNegotiatedProperty(Sasl.QOP);
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport;
|
||||
|
||||
/*
|
||||
* This exception is used to track exceptions in TSaslTransport
|
||||
* that does not have Sasl signature in their stream.
|
||||
*/
|
||||
public class TSaslTransportException extends TTransportException {
|
||||
|
||||
public TSaslTransportException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TSaslTransportException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TSaslTransportException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TSaslTransportException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user