Skip to content
New issue

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

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

Already on GitHub? # to your account

Event will get wrong ProviderInfo when use reuses client transport. #99

Closed
ujjboy opened this issue May 8, 2018 · 1 comment
Closed
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ujjboy
Copy link
Member

ujjboy commented May 8, 2018

Describe the bug

ClientSyncReceiveEvent may get the wrong ProviderInfo when use reuses client transport with the same remote address.

Expected behavior

When two consumer config (for example A and B) get the same address which provides this A and B two services. They will use same client transport.

And after invoke, It will post ClientSyncReceiveEvent with provider info to the event bus.

Actual behavior

Now in BoltClientTransport, code like this:

if (EventBus.isEnable(ClientSyncReceiveEvent.class)) {
    EventBus.post(new ClientSyncReceiveEvent(transportConfig.getConsumerConfig(),
         transportConfig.getProviderInfo(), request, response, throwable));
}

If this client transport is initial for A, transportConfig.getProviderInfo() is provider info of A, and will be reused by B. When invoke by B, transportConfig.getProviderInfo() will also return provider info of A, It needs fixing.

Environment

  • SOFARPC version: 5.3.2
@ujjboy ujjboy added the bug Something isn't working label May 8, 2018
@ujjboy ujjboy self-assigned this May 8, 2018
@leizhiyuan
Copy link
Contributor

one possible solution

when generate map key,we add consumerConfig interface and uniqId

com.alipay.sofa.rpc.transport.ReusableClientTransportHolder#getClientTransport

@Override
    public ClientTransport getClientTransport(ClientTransportConfig config) {
        String key = getAddr(config); //here we make key unique
        ClientTransport transport = clientTransportMap.get(key);
        if (transport == null) {
            transport = ExtensionLoaderFactory.getExtensionLoader(ClientTransport.class)
                .getExtension(config.getContainer(),
                    new Class[] { ClientTransportConfig.class },
                    new Object[] { config });
            ClientTransport oldTransport = clientTransportMap.putIfAbsent(key, transport); // 保存唯一长连接
            if (oldTransport != null) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Multiple threads init ClientTransport with same key:" + key);
                }
                transport.destroy(); //如果同时有人插入,则使用第一个
                transport = oldTransport;
            }
        }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants