TUN-6777: Fix race condition in TestFunnelIdleTimeout
This commit is contained in:
		
							parent
							
								
									b457cca1e5
								
							
						
					
					
						commit
						b1995b4dd1
					
				|  | @ -264,11 +264,14 @@ func testICMPRouterRejectNotEcho(t *testing.T, srcDstIP netip.Addr, msgs []icmp. | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type echoFlowResponder struct { | type echoFlowResponder struct { | ||||||
|  | 	lock     sync.Mutex | ||||||
| 	decoder  *packet.ICMPDecoder | 	decoder  *packet.ICMPDecoder | ||||||
| 	respChan chan []byte | 	respChan chan []byte | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (efr *echoFlowResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) error { | func (efr *echoFlowResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) error { | ||||||
|  | 	efr.lock.Lock() | ||||||
|  | 	defer efr.lock.Unlock() | ||||||
| 	copiedPacket := make([]byte, len(pk.Data)) | 	copiedPacket := make([]byte, len(pk.Data)) | ||||||
| 	copy(copiedPacket, pk.Data) | 	copy(copiedPacket, pk.Data) | ||||||
| 	efr.respChan <- copiedPacket | 	efr.respChan <- copiedPacket | ||||||
|  | @ -276,6 +279,8 @@ func (efr *echoFlowResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) er | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (efr *echoFlowResponder) Close() error { | func (efr *echoFlowResponder) Close() error { | ||||||
|  | 	efr.lock.Lock() | ||||||
|  | 	defer efr.lock.Unlock() | ||||||
| 	close(efr.respChan) | 	close(efr.respChan) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue