From 9b80494c8ef63dcf4c72df2fe3b7d0dd70b81562 Mon Sep 17 00:00:00 2001 From: Laura Henning Date: Tue, 31 Oct 2023 11:42:47 +0100 Subject: [PATCH] Fix blocking of PFCP reception due to EventChannel error --- pfcpUdp/udp.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pfcpUdp/udp.go b/pfcpUdp/udp.go index e684ca4..6b8d5fd 100644 --- a/pfcpUdp/udp.go +++ b/pfcpUdp/udp.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "sync" + "time" "github.com/free5gc/pfcp" "github.com/free5gc/pfcp/logger" @@ -96,12 +97,16 @@ func (pfcpServer *PfcpServer) ReadFrom() (*Message, error) { } if tx != nil { // tx != nil => Already Replied => Resend Request - tx.EventChannel <- pfcp.ReceiveEvent{ + select { + case tx.EventChannel <- pfcp.ReceiveEvent{ Type: pfcp.ReceiveEventTypeResendRequest, RemoteAddr: addr, RcvMsg: pfcpMsg, + }: + return msg, ErrReceivedResentRequest + case <-time.After(2 * time.Second): + return msg, fmt.Errorf("send to EventChannel timeout for tx %d", tx.SequenceNumber) } - return msg, ErrReceivedResentRequest } else { // tx == nil => New Request return msg, nil @@ -111,11 +116,14 @@ func (pfcpServer *PfcpServer) ReadFrom() (*Message, error) { if err != nil { return msg, err } - - tx.EventChannel <- pfcp.ReceiveEvent{ + select { + case tx.EventChannel <- pfcp.ReceiveEvent{ Type: pfcp.ReceiveEventTypeValidResponse, RemoteAddr: addr, RcvMsg: pfcpMsg, + }: + case <-time.After(2 * time.Second): + return msg, fmt.Errorf("send to EventChannel timeout for tx %d", tx.SequenceNumber) } }