Question on Concurrency

In the file, free5gc\NFs\n3iwf\internal\ngap\handler\handler.go
the code segment in the func HandleDownlinkNASTransport

maxRetryTimes := 3
for i := 0; i < maxRetryTimes; i++ {
if n3iwfUe.TCPConnection == nil {
if i == (maxRetryTimes - 1) {
ngapLog.Warn(
“No connection found for UE to send NAS message. This message will be cached in N3IWF”)
n3iwfUe.TemporaryCachedNASMessage = nasEnv
return
} else {
ngapLog.Warn(“No NAS signalling session found, retry…”)
}
time.Sleep(500 * time.Millisecond)
} else {
break
}
}

When the condition (n3iwfUe.TCPConnection == nil) is TRUE and while the thread is asleep
the UE TCP connects to N3IWF by executing the code in the file
free5gc\NFs\n3iwf\internal\nwucp\service\service.go in the function func listenAndServe(tcpListener net.Listener)
and the statement executes
ue.TCPConnection = connection

Would the n3iwfUe.TCPConnection == nil evaluate to FALSE on the next waking up thread.

I am not familiar with GO. I just do not see this happening.

Hi @sabdallah,
I assume you are referring to v1.1.0 of n3iwf, and the answer to this question is yes. The variable n3iwfUe is passed by reference (memory location) rather than passed by value, there might be another event or function that changes its value while this thread sleeping. Once the thread wakes up the outcome of “n3iwfUe.TCPConnection == nil” becomes FALSE since it reads the value from the memory location again, and the value has been changed. By the way, we have updated the free5GC to v3.3.0 using v1.2.0 of n3iwf, this part has been refactored. It would be nice if you check that out too.
BRs,
Linpoyi