I don't know if there is a bug in either nrf9x_socket_offload_close, nrf_close, or our usage of the modem.
It seems to be that if we power off the modem and deinitialise the modem-library, and afterwards reinitialise the modem and the libary there seems to be a problem if we in other parts of the application tries to close a socket.
When calling zsock_close, nrf9x_socket_offload_close will call nrf_close, but nrf_close returns -1 with errno=EBADFS. That results in nrf9x_socket_offload_close not releasing the context. The real problem with that happens afterwards when we open the socket again, but the socket events doesnt work. Currently we have a workaround by wrapping nrf_close to return 0 if errno=EBADFS.
Is that a bug or do we do something "illegal" in our implementation? Sometimes we restart the modem if we lose connect to the network, but that could probably be handled differently.