Skip to content

Commit

Permalink
Only throws exception when exporting service
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Oct 17, 2023
1 parent a4a3fd7 commit 398eb94
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public int getDefaultPort() {

@Override
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
startQosServer(invoker.getUrl());
startQosServer(invoker.getUrl(), true);
return protocol.export(invoker);
}

@Override
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
startQosServer(url);
startQosServer(url, false);
return protocol.refer(type, url);
}

Expand All @@ -96,7 +96,7 @@ public List<ProtocolServer> getServers() {
return protocol.getServers();
}

private void startQosServer(URL url) throws RpcException {
private void startQosServer(URL url, boolean isServer) throws RpcException {
boolean qosCheck = url.getParameter(QOS_CHECK, false);

try {
Expand Down Expand Up @@ -134,13 +134,18 @@ private void startQosServer(URL url) throws RpcException {

} catch (Throwable throwable) {
logger.warn(QOS_FAILED_START_SERVER, "", "", "Fail to start qos server: ", throwable);
try {
stopServer();
} catch (Throwable stop) {
logger.warn(QOS_FAILED_START_SERVER, "", "", "Fail to stop qos server: ", stop);
}

if (qosCheck) {
throw new RpcException(throwable);
try {
// Stop QoS Server to support re-start if Qos-Check is enabled
stopServer();
} catch (Throwable stop) {
logger.warn(QOS_FAILED_START_SERVER, "", "", "Fail to stop qos server: ", stop);
}
if (isServer) {
// Only throws exception when export services
throw new RpcException(throwable);
}
}
}
}
Expand Down

0 comments on commit 398eb94

Please sign in to comment.