apache / rocketmq-client-go

Apache RocketMQ go client

Home Page:https://rocketmq.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate RPC callback and unnecessary lock in RequestResponseFuture

wgdzlh opened this issue · comments

BUG REPORT

  1. Should only invoke callback when rrf is timout, as in Java client, or the callback will be called twice when RPC is finished normally:
    if rrf.IsTimeout() {
    rrf.CauseErr = fmt.Errorf("correlationId:%s request timeout, no reply message", s)
    }
    rrf.ExecuteRequestCallback()

https://github.com/apache/rocketmq/blob/e7f29798ece70e218f7233a7ec85f01e8706a062/client/src/main/java/org/apache/rocketmq/client/producer/RequestFutureHolder.java#L67

  1. Since we already use chan Done to sync the write and read of response message, there is no need to use mutex:

    case <-rf.Done:
    rf.mtx.RLock()
    rf.mtx.RUnlock()
    return rf.ResponseMsg, nil
    }
    }
    func (rf *RequestResponseFuture) PutResponseMessage(message *primitive.Message) {
    rf.mtx.Lock()
    defer rf.mtx.Unlock()
    rf.ResponseMsg = message
    close(rf.Done)
    }

  2. Consider edge cases, we should add non-blocking check of chan Done before calculate timeout, to avoid any possibility of duplicate callback:

    func (rf *RequestResponseFuture) IsTimeout() bool {
    diff := time.Since(rf.BeginTime)
    return diff > rf.Timeout
    }