avoid deadlock in syncMap.Iterate (#909)
Previously, when syncMap iterates a list of records which have the same content in different order, a deadlock might happen. By enforcing a certain order, the deadlock can be avoided.
This commit is contained in:
		@@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"encoding/base64"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"sort"
 | 
			
		||||
 | 
			
		||||
	"github.com/micro/go-micro/store"
 | 
			
		||||
	ckv "github.com/micro/go-micro/store/etcd"
 | 
			
		||||
@@ -94,6 +95,10 @@ func (m *syncMap) Iterate(fn func(key, val interface{}) error) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sort.Slice(keyvals, func(i, j int) bool {
 | 
			
		||||
		return keyvals[i].Key < keyvals[j].Key
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	for _, keyval := range keyvals {
 | 
			
		||||
		// lock
 | 
			
		||||
		if err := m.opts.Lock.Acquire(keyval.Key); err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user