Skip to content

Commit

Permalink
Merge pull request #927 from zouyx/feature/fixRouter
Browse files Browse the repository at this point in the history
Fix: Router chain can not build immediately when started
  • Loading branch information
AlexStocks authored Dec 13, 2020
2 parents b505c86 + d934dec commit 19c4c01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion registry/directory/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Test_Destroy(t *testing.T) {
func Test_List(t *testing.T) {
registryDirectory, _ := normalRegistryDir()

time.Sleep(4e9)
time.Sleep(6e9)
assert.Len(t, registryDirectory.List(&invocation.RPCInvocation{}), 3)
assert.Equal(t, true, registryDirectory.IsAvailable())

Expand Down

0 comments on commit 19c4c01

Please sign in to comment.