Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo-6567] fix consumer warning "safe guard client , should not be called ,must have a bug." #6959

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ public interface Constants {
String CHANNEL_CALLBACK_KEY = "channel.callback.invokers.key";

/**
* The initial state for lazy connection
* The initial connect state for lazy connection
*/
String LAZY_CONNECT_INITIAL_STATE_KEY = "connect.lazy.initial.state";

/**
* The default value of lazy connection's initial state: true
* The default value of lazy connection's initial connect state: true
*
* @see #LAZY_CONNECT_INITIAL_STATE_KEY
*/
boolean DEFAULT_LAZY_CONNECT_INITIAL_STATE = true;

/**
* The close state for lazy connection
*/
String LAZY_CLOSE_STATE_KEY = "close.lazy.state";

String OPTIMIZER_KEY = "optimizer";

String ON_CONNECT_KEY = "onconnect";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.apache.dubbo.remoting.Constants.SEND_RECONNECT_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_LAZY_CONNECT_INITIAL_STATE;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_CONNECT_INITIAL_STATE_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_CLOSE_STATE_KEY;

/**
* dubbo protocol support class.
Expand All @@ -57,15 +58,21 @@ final class LazyConnectExchangeClient implements ExchangeClient {
/**
* lazy connect, initial state for connection
*/
private final boolean initialState;
private final boolean initialConnectState;
private final Boolean closeState;
private volatile ExchangeClient client;
private AtomicLong warningcount = new AtomicLong(0);

public LazyConnectExchangeClient(URL url, ExchangeHandler requestHandler) {
// lazy connect, need set send.reconnect = true, to avoid channel bad status.
this.url = url.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
this.requestHandler = requestHandler;
this.initialState = url.getParameter(LAZY_CONNECT_INITIAL_STATE_KEY, DEFAULT_LAZY_CONNECT_INITIAL_STATE);
this.initialConnectState = url.getParameter(LAZY_CONNECT_INITIAL_STATE_KEY, DEFAULT_LAZY_CONNECT_INITIAL_STATE);
if (url.hasParameter(LAZY_CLOSE_STATE_KEY)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.closeState = null; if (url.hasParameter(LAZY_CLOSE_STATE_KEY)) { this.closeState = Boolean.parseBoolean(url.getParameter(LAZY_CLOSE_STATE_KEY)); }

this.closeState = Boolean.parseBoolean(url.getParameter(LAZY_CLOSE_STATE_KEY));
} else {
this.closeState = null;
}
this.requestWithWarning = url.getParameter(REQUEST_WITH_WARNING_KEY, false);
}

Expand Down Expand Up @@ -150,7 +157,7 @@ public ChannelHandler getChannelHandler() {
@Override
public boolean isConnected() {
if (client == null) {
return initialState;
return initialConnectState;
} else {
return client.isConnected();
}
Expand Down Expand Up @@ -184,10 +191,14 @@ public void send(Object message, boolean sent) throws RemotingException {

@Override
public boolean isClosed() {
if (client != null) {
return client.isClosed();
} else {
if (closeState != null) {
return closeState;
}

if (client == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return client == null ? false : client.isClosed();

return false;
} else {
return client.isClosed();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.apache.dubbo.remoting.Constants.SEND_RECONNECT_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_CLOSE_STATE_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.LAZY_CONNECT_INITIAL_STATE_KEY;

/**
Expand Down Expand Up @@ -180,6 +181,7 @@ public void startClose() {
private void replaceWithLazyClient() {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
URL lazyUrl = url.addParameter(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
.addParameter(LAZY_CLOSE_STATE_KEY, Boolean.TRUE)
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString())
.addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);
Expand Down