Error when using date_time_ntp in NCS 2.4.0

Hi, 

I inquired about the related project in NCS2.3.0 with nRF7002-DK.
Error when using date_time on wifi 

There was a problem when I updated it to NCS2.4.0.

The error occurred as shown below.

[00:00:11.323,516] <err> net_sntp: Failed to create UDP socket 23

[00:00:11.324,127] <wrn> date_time: sntp_init, error: -23

[00:00:11.324,157] <err> net_sock: invalid access on sock -1 by thread 0x200023b8

[00:00:11.336,303] <err> net_sntp: Failed to create UDP socket 23

[00:00:11.336,303] <wrn> date_time: sntp_init, error: -23

[00:00:11.336,303] <err> net_sock: invalid access on sock -1 by thread 0x200023b8

The UDP error occurs at \v2.4.0\zephyr\subsys\net\lib\sntp\sntp.c

int sntp_init(struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len)
{
	int ret;

	if (!ctx || !addr) {
		return -EFAULT;
	}

	memset(ctx, 0, sizeof(struct sntp_ctx));

	ctx->sock.fd = zsock_socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
	if (ctx->sock.fd < 0) {
		NET_ERR("Failed to create UDP socket %d", errno);
		return -errno;
	}

	ret = zsock_connect(ctx->sock.fd, addr, addr_len);
	if (ret < 0) {
		(void)zsock_close(ctx->sock.fd);
		NET_ERR("Cannot connect to UDP remote : %d", errno);
		return -errno;
	}

	ctx->sock.fds[ctx->sock.nfds].fd = ctx->sock.fd;
	ctx->sock.fds[ctx->sock.nfds].events = POLLIN;
	ctx->sock.nfds++;

	return 0;
}

zsock_socket uses z_impl_zsock_socket.

z_impl_zsock_socket seems to need POSIX.

So I use CONFIG_NET_SOCKETS_POSIX_NAMES, but it doesn't seem to work.

Is there a bug in NCS 2.4.0 or do I need additional settings?

I am attaching the tested code.
You need to change ssid and password.

sta_date_time_240.zip

Thank you.

  • Hi

    Due to the summer vacation period we are currently understaffed, so delayed replies must be expected. I am sorry about any inconvenience this might cause.

    Can you using CONFIG_POSIX_MAX_FDS=10 and CONFIG_NET_SOCKETS_POLL_MAX=10. And potentially increasing these in your project config file to allow for more pages to be open? Error -23 points to there being a file table overflow with too many files running at the same time, and since your project has set NET_SOCKETS_POLL_MAX to 10 by default that might be why you're seeing this issue on your end.

    Best regards,

    Simon

Related