Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix: Router chain can not build immediately when started #927

Merged
merged 2 commits into from
Dec 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Trigger init router for first call
  • Loading branch information
zouyx committed Dec 11, 2020
commit 2a924dcb5baec4a7bfa41df4fd50236a53741752
9 changes: 9 additions & 0 deletions cluster/router/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type RouterChain struct {
notify chan struct{}
// Address cache
cache atomic.Value
// init
init sync.Once
}

// Route Loop routers in RouterChain and call Route method to determine the target invokers list.
Expand Down Expand Up @@ -111,6 +113,13 @@ func (c *RouterChain) SetInvokers(invokers []protocol.Invoker) {
c.invokers = invokers
c.mutex.Unlock()

// it should trigger init router for first call
c.init.Do(func() {
go func() {
c.notify <- struct{}{}
}()
})

c.count++
now := time.Now()
if c.count >= countThreshold && now.Sub(c.last) >= timeThreshold {
Expand Down