diff --git a/CHANGELOG b/CHANGELOG index f0fc19a..b5c3541 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,7 +9,7 @@ v6.1 TOU提供了TCP over UDP,多种自定义加密UDP方式传输TCP数据. 5.优化了DST,防止意外crash. 6.修复了mapx的Keys()方法的bug导致内网穿透bridge不稳定的问题. - +7.修复了部分服务不能绑定IPv6地址的bug. v6.0 企业版开源啦 本次更新主要是把企业版开源,把企业版代码合并到现在的开源goproxy当中,继续遵循GPLv3,免费开源, diff --git a/utils/mapx/map.go b/utils/mapx/map.go index df89c31..cd07511 100644 --- a/utils/mapx/map.go +++ b/utils/mapx/map.go @@ -152,14 +152,7 @@ type Tuple struct { func (m ConcurrentMap) Iter() <-chan Tuple { chans := snapshot(m) ch := make(chan Tuple) - go func() { - defer func() { - if e := recover(); e != nil { - fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) - } - }() - fanIn(chans, ch) - }() + go fanIn(chans, ch) return ch } @@ -171,14 +164,7 @@ func (m ConcurrentMap) IterBuffered() <-chan Tuple { total += cap(c) } ch := make(chan Tuple, total) - go func() { - defer func() { - if e := recover(); e != nil { - fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) - } - }() - fanIn(chans, ch) - }() + go fanIn(chans, ch) return ch } @@ -193,11 +179,6 @@ func snapshot(m ConcurrentMap) (chans []chan Tuple) { // Foreach shard. for index, shard := range m { go func(index int, shard *ConcurrentMapShared) { - defer func() { - if e := recover(); e != nil { - fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) - } - }() // Foreach key, value pair. shard.RLock() chans[index] = make(chan Tuple, len(shard.items)) @@ -215,22 +196,25 @@ func snapshot(m ConcurrentMap) (chans []chan Tuple) { // fanIn reads elements from channels `chans` into channel `out` func fanIn(chans []chan Tuple, out chan Tuple) { + defer func() { + if e := recover(); e != nil { + fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) + } + }() wg := sync.WaitGroup{} wg.Add(len(chans)) for _, ch := range chans { - go func() { + go func(ch chan Tuple) { defer func() { if e := recover(); e != nil { fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) } }() - func(ch chan Tuple) { - for t := range ch { - out <- t - } - wg.Done() - }(ch) - }() + for t := range ch { + out <- t + } + wg.Done() + }(ch) } wg.Wait() close(out) @@ -281,22 +265,20 @@ func (m ConcurrentMap) Keys() []string { wg := sync.WaitGroup{} wg.Add(SHARD_COUNT) for _, shard := range m { - go func() { + go func(shard *ConcurrentMapShared) { defer func() { if e := recover(); e != nil { fmt.Printf("crashed, err: %s\nstack:%s", e, string(debug.Stack())) } }() - func(shard *ConcurrentMapShared) { - // Foreach key, value pair. - shard.RLock() - for key := range shard.items { - ch <- key - } - shard.RUnlock() - wg.Done() - }(shard) - }() + // Foreach key, value pair. + shard.RLock() + for key := range shard.items { + ch <- key + } + shard.RUnlock() + wg.Done() + }(shard) } wg.Wait() close(ch)