Skip to content

Callback mode rpc context loss, which also affects link tracking #12773

@wuwen5

Description

@wuwen5
  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.1.x
  • Operating System version: mac os\Linux
  • Java version: 1.8

Steps to reproduce this issue

  1. Server
public interface DemoApi {

    String methodA();

    String testCallbackMethod(String name,  ApiCallback callback);
    
    interface ApiCallback {
        String callbackMethod();
    }
}

@DubboService(methods = @Method(name="testCallbackMethod", 
                arguments = {@Argument(index = 1, type = "DemoApi$ApiCallback", callback = true)}))
public class DemoProvider implements DemoApi {
   
    @Override
    public String methodA() {
        return "ok";
    }
  
  @Override
    public String testCallbackMethod(String name, ApiCallback callback) {
        String s = callback.callbackMethod();
        return "ok";
    }
}
  1. Consumer
@RestController
public class TestController{

    @DubboReference
    DemoApi demo;

    private DemoApi.ApiCallback callback = new DemoApi.ApiCallback() {
        @Override
        public String callbackMethod() {
            //rpc context has been lost
            System.out.println("callback:" + RpcContext.getContext().getAttachment("test"));
            //This is just a simple simulation problem, in fact, it may call other services
            return demo.methodA();
        }
    };

    @GetMapping("/testDubboCallback")
    public ResponseEntity<String> testDubboCallback() {
        RpcContext.getContext().setAttachment("test", "abc");
        return ResponseEntity.ok(demo.testCallbackMethod("param" ,callback));
    }

}

Pls. provide [GitHub address] to reproduce this issue.

Expected Behavior

RpcContext passed normally, sky tracking is normal.

Actual Behavior

rpc context loss, the tracking has been broken.

If there is an exception, please attach the exception trace:

Just put your stack trace here!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugBugs to being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions