After many hours of successful LTE connections and using the AF_LTE socket just fine (many creates, many send/receive, many closes), my application now hangs on a call to socket(AF_LTE,0,NPROTO_AT). Hung, as in the call to socket() does not return. I have no idea where to look to resolve this. Is the nrfxlib code available for review? I'll sign an NDA if I can get my eyes on it. I've spent way too much time trying to code around strange behavior in nrfxlib/nrf/zephyr.
This is running on nrf9160 DK, modem fw v1.1.1 and NCS v1.2.0
I can not give you access to the bsdlib source code. However, I can try to help you find the source of the problem.
Do you use the at_cmd library to send AT commands?
Do you see similar behavior on other types of sockets?
How many other sockets are you using (and are you using the lwm2m_carrier library or other libraries that might use sockets)?
Are you able to capture a modem trace that captures the problem?
I do not use at_cmd, I rolled my own (prior to when the at_* libs were mature enough for my use)
I have seen various socket issues over the past several months and have several tickets in devzone. They have all(?) been resolved by now.
I should have no more than 3 sockets open at once (AF_LTE for monitoring the modem is always open and normally waiting on recv(); AF_LTE for commanding the modem, only occasionally; AF_INET for send/recv of UDP data once we are connected to the network). My occasional AF_LTE socket for commanding keeps getting fd=1 or 2 when created, so I don't think I am leaking them anyplace. I'm not using any additional libs that should be using sockets (and not using lwm2m_carrier).
This happens very infrequently and I cannot get modem traces as my application also uses the nrf52840 on the DK.
I'm curious what the socket call might be doing that would cause it to hang? I can deal with errors, but hanging threads is much more difficult. If you can't share the bsdlib source, can you give some insight to what may be happening?
miked531 said:I cannot get modem traces as my application also uses the nrf52840 on the DK.
It should not be a problem that you are using the nRF52840 on the DK, as long as P1.12 is kept low, and you do not use UART1/SPI1/TWI1 on the nRF9160.
miked531 said:This happens very infrequently
Do you know if there is anything different with the ones where it hangs? Does it happen regularly or at random intervals?
We are currently investigating a very similar problem that also leads to socket() hanging. However, in that case, we are trying to open a TLS socket, and it happens very consistently.
One thing you could try is to use the previous version of bsdlib. You can do that by changing the revision of nrfxlib on line 72 in ncs/nrf/west.yml from 1.2.0 to 3e381d09f1d305e230435f5b6e4c9ef928b6a697, then running "west update".
Sorry for the delay, I have been on vacation.
I would be happy to get the modem traces, but I do use UART1 in my app. I have captured traces before, but it involved programming the 52840. If you have different instructions, please point me to then and I'll try.
I have only seen the socket() call hang on less than 5 occasions and I nothing looked different when it happened, though I didn't do an exhaustive check. I do encounter other issues when I don't receive a response from the modem and it happens more frequently (perhaps 1/20 times). That sequence is simply:
The timeout is 5 seconds and the recv() does not timeout, but rather hangs indefinitely. The only other modem-related activity at the time is that I have a separate thread running to monitor signal strength, waiting on a recv().
I'll have to try the older nrfxlib, but cannot for several weeks.
miked531 said: I have captured traces before, but it involved programming the 52840
I assume you are talking about point 2 in this guide: https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/how-to-get-modem-trace-using-trace-collector-in-nrf-connect ?
The reason why that point is there is that the board controller decides if the pins used by UART_1 (which is the UART peripheral used for the modem trace) are routed to the on-board debugger, which forwards them over USB, or to the arduino headers.
The board controller does this by setting P1.12 high (or not). The default is that UART_1 is routed to the on-board debugger. The board controller will configure the pins used for bord control during startup, based on the values of a set of Kconfig options. Therefore, as long as you do not use those pins in your application, and you have not set CONFIG_BOARD_PCA10090_UART1_ARDUINO=y. Other than that one pin, it does not matter what is running on the board controller.
Though technically, you don't even have to use UART_1, or the UART_1 pins. You can change those details in the ncs/nrf/lib/bsdlib/bsd_os.c file. You can find more information about what is happening in that file here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.2.0/nrfxlib/bsdlib/doc/ug_bsdlib_porting_os.html
However, that would probably require a different way of collecting the trace on the computer side than the Trace Collector application.