<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<p dir="auto">Dubbo version: 2.6.2<br>
Operating System version: win7<br>
Java version: 1.8</p>
<h3 dir="auto">Step to reproduce this issue</h3>
<p dir="auto">阅读源码发现，每个代理实现类都会去判断默认实现</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class Protocol$Adaptive implements org.apache.dubbo.rpc.Protocol
{
    public void destroy()
    {
        throw new UnsupportedOperationException(
                &quot;method public abstract void org.apache.dubbo.rpc.Protocol.destroy() of interface org.apache.dubbo.rpc.Protocol is not adaptive method!&quot;);
    }

    public int getDefaultPort()
    {
        throw new UnsupportedOperationException(
                &quot;method public abstract int org.apache.dubbo.rpc.Protocol.getDefaultPort() of interface org.apache.dubbo.rpc.Protocol is not adaptive method!&quot;);
    }

    public org.apache.dubbo.rpc.Invoker refer(java.lang.Class arg0, org.apache.dubbo.common.URL arg1)
        throws org.apache.dubbo.rpc.RpcException
    {
        if (arg1 == null)
            throw new IllegalArgumentException(&quot;url == null&quot;);
        org.apache.dubbo.common.URL url = arg1;
        String extName = (url.getProtocol() == null ? &quot;dubbo&quot; : url.getProtocol());
        if (extName == null)
            throw new IllegalStateException(&quot;Fail to get extension(org.apache.dubbo.rpc.Protocol) name from url(&quot;
                    + url.toString() + &quot;) use keys([protocol])&quot;);
        org.apache.dubbo.rpc.Protocol extension = (org.apache.dubbo.rpc.Protocol) ExtensionLoader
                .getExtensionLoader(org.apache.dubbo.rpc.Protocol.class).getExtension(extName);
        return extension.refer(arg0, arg1);
    }

    public org.apache.dubbo.rpc.Exporter export(org.apache.dubbo.rpc.Invoker arg0)
        throws org.apache.dubbo.rpc.RpcException
    {
        if (arg0 == null)
            throw new IllegalArgumentException(&quot;org.apache.dubbo.rpc.Invoker argument == null&quot;);
        if (arg0.getUrl() == null)
            throw new IllegalArgumentException(&quot;org.apache.dubbo.rpc.Invoker argument getUrl() == null&quot;);
        org.apache.dubbo.common.URL url = arg0.getUrl();
        String extName = (url.getProtocol() == null ? &quot;dubbo&quot; : url.getProtocol());
        if (extName == null)
            throw new IllegalStateException(&quot;Fail to get extension(org.apache.dubbo.rpc.Protocol) name from url(&quot;
                    + url.toString() + &quot;) use keys([protocol])&quot;);
        org.apache.dubbo.rpc.Protocol extension = (org.apache.dubbo.rpc.Protocol) ExtensionLoader
                .getExtensionLoader(org.apache.dubbo.rpc.Protocol.class).getExtension(extName);
        return extension.export(arg0);
    }
}"><pre class="notranslate"><code class="notranslate">public class Protocol$Adaptive implements org.apache.dubbo.rpc.Protocol
{
    public void destroy()
    {
        throw new UnsupportedOperationException(
                "method public abstract void org.apache.dubbo.rpc.Protocol.destroy() of interface org.apache.dubbo.rpc.Protocol is not adaptive method!");
    }

    public int getDefaultPort()
    {
        throw new UnsupportedOperationException(
                "method public abstract int org.apache.dubbo.rpc.Protocol.getDefaultPort() of interface org.apache.dubbo.rpc.Protocol is not adaptive method!");
    }

    public org.apache.dubbo.rpc.Invoker refer(java.lang.Class arg0, org.apache.dubbo.common.URL arg1)
        throws org.apache.dubbo.rpc.RpcException
    {
        if (arg1 == null)
            throw new IllegalArgumentException("url == null");
        org.apache.dubbo.common.URL url = arg1;
        String extName = (url.getProtocol() == null ? "dubbo" : url.getProtocol());
        if (extName == null)
            throw new IllegalStateException("Fail to get extension(org.apache.dubbo.rpc.Protocol) name from url("
                    + url.toString() + ") use keys([protocol])");
        org.apache.dubbo.rpc.Protocol extension = (org.apache.dubbo.rpc.Protocol) ExtensionLoader
                .getExtensionLoader(org.apache.dubbo.rpc.Protocol.class).getExtension(extName);
        return extension.refer(arg0, arg1);
    }

    public org.apache.dubbo.rpc.Exporter export(org.apache.dubbo.rpc.Invoker arg0)
        throws org.apache.dubbo.rpc.RpcException
    {
        if (arg0 == null)
            throw new IllegalArgumentException("org.apache.dubbo.rpc.Invoker argument == null");
        if (arg0.getUrl() == null)
            throw new IllegalArgumentException("org.apache.dubbo.rpc.Invoker argument getUrl() == null");
        org.apache.dubbo.common.URL url = arg0.getUrl();
        String extName = (url.getProtocol() == null ? "dubbo" : url.getProtocol());
        if (extName == null)
            throw new IllegalStateException("Fail to get extension(org.apache.dubbo.rpc.Protocol) name from url("
                    + url.toString() + ") use keys([protocol])");
        org.apache.dubbo.rpc.Protocol extension = (org.apache.dubbo.rpc.Protocol) ExtensionLoader
                .getExtensionLoader(org.apache.dubbo.rpc.Protocol.class).getExtension(extName);
        return extension.export(arg0);
    }
}
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/wiki/FAQ">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.0-SNAPSHOT</li>
<li>Operating System version: mac os</li>
<li>Java version: 1.8</li>
</ul>
<h3 dir="auto">Step to reproduce this issue</h3>
<ol dir="auto">
<li>Export a service</li>
<li>Make cluster = "forking"</li>
<li>Set Attachment in RpcContext</li>
<li>Do rpc invoke</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">The attachment in RpcContext has element.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">The attachment in RpcContext don't have element.</p>
<h3 dir="auto">The problem</h3>
<p dir="auto">I set attachment in the consumer side like this:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12047600/42265457-30483704-7fa6-11e8-8075-2eede7775b3a.png"><img src="https://user-images.githubusercontent.com/12047600/42265457-30483704-7fa6-11e8-8075-2eede7775b3a.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Then do rpc invoke,but the attachment is missing, (AbstractInvoker#invoke):<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12047600/42265551-6b74d300-7fa6-11e8-8ad6-359cf091a3ac.png"><img src="https://user-images.githubusercontent.com/12047600/42265551-6b74d300-7fa6-11e8-8ad6-359cf091a3ac.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">The problem is that ForkingClusterInvoker use threapool to do rpc invoke which will miss the threadlocal:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12047600/42265595-92dae95c-7fa6-11e8-8ae3-3332cc67e4d3.png"><img src="https://user-images.githubusercontent.com/12047600/42265595-92dae95c-7fa6-11e8-8ae3-3332cc67e4d3.png" alt="image" style="max-width: 100%;"></a></p>