Closed twz915 closed 10 months ago
When ctx time out, r.ctx.Done() returns (line 63->65), causing a normal response to return an error as well
r.ctx.Done()
https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L60-L66
So we should close(responseFuture.Done) before responseFuture.executeInvokeCallback()
close(responseFuture.Done)
responseFuture.executeInvokeCallback()
https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/remote_client.go#L232-L236
A simple way to reproduce this is to add time.Sleep(time.Second*3) before if r.callback != nil, then callback return get resp.Err, which is not nil (because the context timeout, resp.Err was changed to ctx timeout error)
time.Sleep(time.Second*3)
if r.callback != nil
https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L47-L53
that is, r was changed by context timeout
r
https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L63-L66
So response future should close channel before callback (that is, put the callback at the end of the entire calling process)
What is the purpose of the change
When ctx time out,
r.ctx.Done()
returns (line 63->65), causing a normal response to return an error as wellhttps://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L60-L66
So we should
close(responseFuture.Done)
beforeresponseFuture.executeInvokeCallback()
https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/remote_client.go#L232-L236
A simple way to reproduce this is to add
time.Sleep(time.Second*3)
beforeif r.callback != nil
, then callback return get resp.Err, which is not nil (because the context timeout, resp.Err was changed to ctx timeout error)https://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L47-L53
that is,
r
was changed by context timeouthttps://github.com/apache/rocketmq-client-go/blob/7ae83c49351a96d78ebccec5dd545f0c05e3d514/internal/remote/future.go#L63-L66
So response future should close channel before callback (that is, put the callback at the end of the entire calling process)