]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix to avoid process wide fcntl calls mixed with nonblocking
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 31 Aug 2022 08:09:39 +0000 (10:09 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 31 Aug 2022 08:09:39 +0000 (10:09 +0200)
  operations after a blocked write.

doc/Changelog
util/netevent.c

index 3525165250c7f25710909c3dbdf93fee6e9c5d70..ed3812c69cb4cb4d9429af74b1087bd5b47d1e7c 100644 (file)
@@ -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.
 
index c2b1ac7d4397b6fa9974e6a485f13b238fd27777..5bc8d8bcde3d9ff6604b6a5d3f4bcb489f9c56f3 100644 (file)
@@ -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) {