mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Fix concurrent map write in tcp.go
This commit is contained in:
		
							parent
							
								
									8fa9b84108
								
							
						
					
					
						commit
						4fba558638
					
				
					 1 changed files with 4 additions and 0 deletions
				
			
		| 
						 | 
					@ -125,8 +125,10 @@ func (iface *tcpInterface) listen() error {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	iface.serv, err = lc.Listen(ctx, "tcp", iface.tcp_addr)
 | 
						iface.serv, err = lc.Listen(ctx, "tcp", iface.tcp_addr)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
 | 
							iface.mutex.Lock()
 | 
				
			||||||
		iface.calls = make(map[string]struct{})
 | 
							iface.calls = make(map[string]struct{})
 | 
				
			||||||
		iface.conns = make(map[tcpInfo](chan struct{}))
 | 
							iface.conns = make(map[tcpInfo](chan struct{}))
 | 
				
			||||||
 | 
							iface.mutex.Unlock()
 | 
				
			||||||
		go iface.listener()
 | 
							go iface.listener()
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -187,7 +189,9 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
 | 
				
			||||||
		if iface.isAlreadyCalling(saddr) {
 | 
							if iface.isAlreadyCalling(saddr) {
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							iface.mutex.Lock()
 | 
				
			||||||
		iface.calls[callname] = struct{}{}
 | 
							iface.calls[callname] = struct{}{}
 | 
				
			||||||
 | 
							iface.mutex.Unlock()
 | 
				
			||||||
		defer func() {
 | 
							defer func() {
 | 
				
			||||||
			// Block new calls for a little while, to mitigate livelock scenarios
 | 
								// Block new calls for a little while, to mitigate livelock scenarios
 | 
				
			||||||
			time.Sleep(default_tcp_timeout)
 | 
								time.Sleep(default_tcp_timeout)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue