From: W.C.A. Wijngaards Date: Wed, 31 Aug 2022 08:09:39 +0000 (+0200) Subject: - Fix to avoid process wide fcntl calls mixed with nonblocking X-Git-Tag: release-1.17.0rc1~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fa1c17cd9d1af515c2fa997726c9433d387f3f3;p=thirdparty%2Funbound.git - Fix to avoid process wide fcntl calls mixed with nonblocking operations after a blocked write. --- diff --git a/doc/Changelog b/doc/Changelog index 352516525..ed3812c69 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +31 August 2022: Wouter + - Fix to avoid process wide fcntl calls mixed with nonblocking + operations after a blocked write. + 22 August 2022: Wouter - Fix #741: systemd socket activation fails on IPv6. diff --git a/util/netevent.c b/util/netevent.c index c2b1ac7d4..5bc8d8bcd 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -379,19 +379,30 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, WSAGetLastError() == WSAENOBUFS || WSAGetLastError() == WSAEWOULDBLOCK) { #endif - int e; - fd_set_block(c->fd); - if (!is_connected) { - sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), - sldns_buffer_remaining(packet), 0, - addr, addrlen); - } else { - sent = send(c->fd, (void*)sldns_buffer_begin(packet), - sldns_buffer_remaining(packet), 0); + /* if we set the fd blocking, other threads suddenly + * have a blocking fd that they operate on */ + while( +#ifndef USE_WINSOCK + errno == EAGAIN || +# ifdef EWOULDBLOCK + errno == EWOULDBLOCK || +# endif + errno == ENOBUFS +#else + WSAGetLastError() == WSAEINPROGRESS || + WSAGetLastError() == WSAENOBUFS || + WSAGetLastError() == WSAEWOULDBLOCK +#endif + ) { + if (!is_connected) { + sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), + sldns_buffer_remaining(packet), 0, + addr, addrlen); + } else { + sent = send(c->fd, (void*)sldns_buffer_begin(packet), + sldns_buffer_remaining(packet), 0); + } } - e = errno; - fd_set_nonblock(c->fd); - errno = e; } } if(sent == -1) { @@ -568,12 +579,21 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, WSAGetLastError() == WSAENOBUFS || WSAGetLastError() == WSAEWOULDBLOCK) { #endif - int e; - fd_set_block(c->fd); - sent = sendmsg(c->fd, &msg, 0); - e = errno; - fd_set_nonblock(c->fd); - errno = e; + while( +#ifndef USE_WINSOCK + errno == EAGAIN || +# ifdef EWOULDBLOCK + errno == EWOULDBLOCK || +# endif + errno == ENOBUFS +#else + WSAGetLastError() == WSAEINPROGRESS || + WSAGetLastError() == WSAENOBUFS || + WSAGetLastError() == WSAEWOULDBLOCK +#endif + ) { + sent = sendmsg(c->fd, &msg, 0); + } } } if(sent == -1) {