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

Fix the problem that the consumer stub event does not trigger #9723

Conversation

BurningCN
Copy link
Member

When the consumer opens the stub, the exposure of the stub service (in the StubProxyWrapper#getProxy method) occurs after the connection between the client and the server is completed, so when the connected or disconnected event in the client is triggered(DubboProtocol#requestHandler ), the stub service cannot be found, so that the related methods of the consumer stub service cannot be called.

received(channel, invocation);
} catch (Throwable t) {
logger.warn("Failed to invoke event method " + invocation.getMethodName() + "(), cause: " + t.getMessage(), t);
}
}
}

private void getOrWaitStubService(Channel channel, Invocation invocation) throws InterruptedException {
try {
Invoker<?> invoker = getInvoker(channel, invocation);
Copy link
Member Author

Choose a reason for hiding this comment

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

If getInvoker throws an exception, it means that the stub service has not been exposed, it will try to wait for the signal that the stub exposure is complete, and then call back the related methods of the stub service.

@@ -253,7 +276,8 @@ private boolean isClientSide(Channel channel) {
// if it's callback service on client side
isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getObjectAttachments().get(STUB_EVENT_KEY));
if (isStubServiceInvoke) {
port = channel.getRemoteAddress().getPort();
// The port of the client exposed stub service is 0
port = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

When the consumer exposes the stub service, the port number is 0

Copy link
Contributor

Choose a reason for hiding this comment

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

One similar PR has been merged into the master branch

#9825

@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2022

Codecov Report

Merging #9723 (73082ca) into 3.0 (8f9d0ee) will increase coverage by 0.19%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##                3.0    #9723      +/-   ##
============================================
+ Coverage     65.60%   65.79%   +0.19%     
- Complexity      295      320      +25     
============================================
  Files          1206     1212       +6     
  Lines         52323    52810     +487     
  Branches       7942     8008      +66     
============================================
+ Hits          34325    34747     +422     
- Misses        14259    14288      +29     
- Partials       3739     3775      +36     
Impacted Files Coverage Δ
...apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java 60.00% <0.00%> (-5.14%) ⬇️
...a/org/apache/dubbo/rpc/filter/AccessLogFilter.java 25.31% <0.00%> (-43.92%) ⬇️
...va/org/apache/dubbo/rpc/support/AccessLogData.java 53.16% <0.00%> (-37.98%) ⬇️
...apache/dubbo/rpc/cluster/merger/MergerFactory.java 71.42% <0.00%> (-24.87%) ⬇️
.../apache/dubbo/rpc/filter/ProfilerServerFilter.java 62.85% <0.00%> (-22.86%) ⬇️
...apache/dubbo/registry/client/ServiceDiscovery.java 40.00% <0.00%> (-20.00%) ⬇️
...apache/dubbo/rpc/protocol/tri/RequestMetadata.java 82.60% <0.00%> (-17.40%) ⬇️
.../registry/multicast/MulticastServiceDiscovery.java 50.00% <0.00%> (-16.67%) ⬇️
...ocol/tri/observer/ClientCallToObserverAdapter.java 32.00% <0.00%> (-14.16%) ⬇️
...che/dubbo/rpc/protocol/tri/stream/StreamUtils.java 58.97% <0.00%> (-13.25%) ⬇️
... and 208 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f9d0ee...73082ca. Read the comment docs.

@@ -702,6 +728,8 @@ public void destroy() {
}
}
referenceClientMap.clear();

stubServiceToLatch.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should take destroy of stubServiceToLatch on destroy of stub proxy too.

There might have lots of proxy invokers (reference config) create and destroy during the lifetime of DubboProtocol.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think waiting for the stub to be ready is necessary for it will make the whole process more complicated. Just giving a more elegant and clear Exception or result would be enough. What do you think? @BurningCN

Copy link
Member Author

Choose a reason for hiding this comment

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

Consider the complexities of latch.await(), Can stubServiceToLatch be replaced with this similar structure, Map<String,Boolean> stubService2Flag.When the connect event occurs and the stub invoker is not found, execute stubService2Flag.put(serviceKey, true).
When the stub service exposure is completed, check if(stubService2Flag.get(serviceKey)), then call received(channel, invocation);

Copy link
Contributor

Choose a reason for hiding this comment

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

Map<String,Boolean> stubService2Flag is still a variable that needs to be taken care of in case of a memory leak. I think a detailed log giving full information of possible causes would be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, then there is no need to wait(stubServiceToLatch) or delay notification(stubService2Flag). If the stub invoker cannot be obtained, just print the detailed log.

@@ -702,6 +728,8 @@ public void destroy() {
}
}
referenceClientMap.clear();

stubServiceToLatch.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should take destroy of stubServiceToLatch on destroy of stub proxy too.

There might have lots of proxy invokers (reference config) create and destroy during the lifetime of DubboProtocol.

@@ -253,7 +276,8 @@ private boolean isClientSide(Channel channel) {
// if it's callback service on client side
isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getObjectAttachments().get(STUB_EVENT_KEY));
if (isStubServiceInvoke) {
port = channel.getRemoteAddress().getPort();
// The port of the client exposed stub service is 0
port = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

One similar PR has been merged into the master branch

#9825

@@ -702,6 +728,8 @@ public void destroy() {
}
}
referenceClientMap.clear();

stubServiceToLatch.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think waiting for the stub to be ready is necessary for it will make the whole process more complicated. Just giving a more elegant and clear Exception or result would be enough. What do you think? @BurningCN

@chickenlj
Copy link
Contributor

Let's change this pull request following this patch #9825.

Besides that, the only thing that needs to do is to add some extra error information.

@BurningCN
Copy link
Member Author

Let's change this pull request following this patch #9825.

Besides that, the only thing that needs to do is to add some extra error information.

OK

@chickenlj chickenlj merged commit feb1792 into apache:3.0 Mar 28, 2022
@chickenlj chickenlj added this to the 3.0.8 milestone Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants