From b1995b4dd16b9936134fa2c0207cef2f62d37256 Mon Sep 17 00:00:00 2001 From: cthuang Date: Tue, 20 Sep 2022 09:10:47 +0100 Subject: [PATCH] TUN-6777: Fix race condition in TestFunnelIdleTimeout --- ingress/origin_icmp_proxy_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ingress/origin_icmp_proxy_test.go b/ingress/origin_icmp_proxy_test.go index b961b7d4..6046c575 100644 --- a/ingress/origin_icmp_proxy_test.go +++ b/ingress/origin_icmp_proxy_test.go @@ -264,11 +264,14 @@ func testICMPRouterRejectNotEcho(t *testing.T, srcDstIP netip.Addr, msgs []icmp. } type echoFlowResponder struct { + lock sync.Mutex decoder *packet.ICMPDecoder respChan chan []byte } func (efr *echoFlowResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) error { + efr.lock.Lock() + defer efr.lock.Unlock() copiedPacket := make([]byte, len(pk.Data)) copy(copiedPacket, pk.Data) efr.respChan <- copiedPacket @@ -276,6 +279,8 @@ func (efr *echoFlowResponder) SendPacket(dst netip.Addr, pk packet.RawPacket) er } func (efr *echoFlowResponder) Close() error { + efr.lock.Lock() + defer efr.lock.Unlock() close(efr.respChan) return nil }