From nobody Mon Oct 16 04:01:06 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S83Lp43tMz4wndt; Mon, 16 Oct 2023 04:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S83Lp3fKyz3fhQ; Mon, 16 Oct 2023 04:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697428866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TrdeD52UaG8ODwUF52Xi/8embO3jt7YQt7Y+IevUbJk=; b=C9teasPrBgzYSbbJnvz2dtLzS+dLUNPDtYznRtYyEPeT+sH+SDUzEJ6/zB2U8bJvQG7Jbk 8389TZb2C1yFu04wJ9tzpaga3xDkwSoT5j2mUbyU+jiKeN5ZjFbxAldPFY9pUL718PxJzR K1bFxDDXWh2pSgdxWsplBjFJCQ5AHVSyOShE0mgWZ+U6dmMTGBt6HR3xEXsuckJ9Mfw6qL xj0IuYJ7oBKvDHqImfMRbl6WfxpJsx954gjnSmKndxqDQ8jztBUcfzOVQ8Qkk3YKbRC11z 2yYjgFrOGZVCFMI2B/2F1k5AnlOzngXQI1Tv6vQVpVwi5NtfCmCio0NCm9OceA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697428866; a=rsa-sha256; cv=none; b=i6R0vJcATUHZw3W7lKy/UaXFkib1eXNnmP3E+YzDVtSowhrm4E0LhqlNO4VP6YTFgmW0QJ BKDYGOYDTsXky5x/jJmwX0/ZtbYo/rgAMxbUx55qSob3cma3/l6I76fb8t3240wlb7lShB ndSvrgxPeIF9oD/qJXa8uAYhFNzlnnHJlgTHY9XG9W4QySpWo0+TomjmbWPlsApYny8jSJ XM9rvwn+fA94pe4pCgwmfKDKnjre1G/Ebi2WxoLNTmuPESxE60Ih9OAE5TCGWmdUIlVQJ1 QLLepp25cKeVFBp16mEBtAgPD63atw71Cd4BVDNkcIreJ8aWVH8lFXehdhvw8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697428866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TrdeD52UaG8ODwUF52Xi/8embO3jt7YQt7Y+IevUbJk=; b=lFDmB8Y35BmmuxorETQ0Rq5Iy/B/hOnDYY4iHcDr1DBqJrpi1On+9H0ZApP/62AY2S8HTx XOFBcIb3Hi3ignDsQuezDNISyZgM0q1XoL/JgFnosDha4cu9qNXXPA1OL+jjLezhzNcGUy 36Dz65WBzLsfHsS/0EpSqZ9NJRQADZuRYNOyWAXkO2b+gBx0hWYDPgH4rqv0VFF5Ny9mqx pS1Zk52Lb5MDXLFMmWOt7ctpBBr1JnHjA+RgYhlArLRtMmCXvoDugDo/KWltGOEPN9qdwR i08jfZcBL7i1sxkmxKZ0RoWETqZTVVK7l3HqzAd0YPJDkvukabhmhcPBdFqOPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S83Lp2j9Hz9h4; Mon, 16 Oct 2023 04:01:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39G416Zo034895; Mon, 16 Oct 2023 04:01:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39G416Zp034892; Mon, 16 Oct 2023 04:01:06 GMT (envelope-from git) Date: Mon, 16 Oct 2023 04:01:06 GMT Message-Id: <202310160401.39G416Zp034892@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: 7d9c0fb57893 - stable/12 - unbound: Import upstream 0ee44ef3 when ENOBUFS is returned List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 7d9c0fb578931f7f622970bad40d799abd74a76f Auto-Submitted: auto-generated The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=7d9c0fb578931f7f622970bad40d799abd74a76f commit 7d9c0fb578931f7f622970bad40d799abd74a76f Author: Cy Schubert AuthorDate: 2023-10-13 00:04:25 +0000 Commit: Cy Schubert CommitDate: 2023-10-13 01:54:35 +0000 unbound: Import upstream 0ee44ef3 when ENOBUFS is returned From upstream 0ee44ef3: - Fix send of udp retries when ENOBUFS is returned. It stops looping and also waits for the condition to go away. Reported by Florian Obser. PR: 274352 Merge commit '292d51198aa319c58f534549851e9c28486abdf4' (cherry picked from commit 6e71235e558ef579605e7f35b02f983b9a246a4a) --- contrib/unbound/.gitignore | 1 + contrib/unbound/util/netevent.c | 102 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/contrib/unbound/.gitignore b/contrib/unbound/.gitignore new file mode 100644 index 000000000000..b25c15b81fae --- /dev/null +++ b/contrib/unbound/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/contrib/unbound/util/netevent.c b/contrib/unbound/util/netevent.c index 204e4883cf27..b9395a8998b9 100644 --- a/contrib/unbound/util/netevent.c +++ b/contrib/unbound/util/netevent.c @@ -116,6 +116,8 @@ /** timeout in millisec to wait for write to unblock, packets dropped after.*/ #define SEND_BLOCKED_WAIT_TIMEOUT 200 +/** max number of times to wait for write to unblock, packets dropped after.*/ +#define SEND_BLOCKED_MAX_RETRY 5 /** Let's make timestamping code cleaner and redefine SO_TIMESTAMP* */ #ifndef SO_TIMESTAMP @@ -402,9 +404,10 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, WSAGetLastError() == WSAENOBUFS || WSAGetLastError() == WSAEWOULDBLOCK) { #endif + int retries = 0; /* if we set the fd blocking, other threads suddenly * have a blocking fd that they operate on */ - while(sent == -1 && ( + while(sent == -1 && retries < SEND_BLOCKED_MAX_RETRY && ( #ifndef USE_WINSOCK errno == EAGAIN || errno == EINTR || # ifdef EWOULDBLOCK @@ -419,6 +422,13 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, #endif )) { #if defined(HAVE_POLL) || defined(USE_WINSOCK) + int send_nobufs = ( +#ifndef USE_WINSOCK + errno == ENOBUFS +#else + WSAGetLastError() == WSAENOBUFS +#endif + ); struct pollfd p; int pret; memset(&p, 0, sizeof(p)); @@ -457,8 +467,48 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, log_err("poll udp out failed: %s", sock_strerror(errno)); return 0; + } else if((pret < 0 && +#ifndef USE_WINSOCK + errno == ENOBUFS +#else + WSAGetLastError() == WSAENOBUFS +#endif + ) || (send_nobufs && retries > 0)) { + /* ENOBUFS, and poll returned without + * a timeout. Or the retried send call + * returned ENOBUFS. It is good to + * wait a bit for the error to clear. */ + /* The timeout is 20*(2^(retries+1)), + * it increases exponentially, starting + * at 40 msec. After 5 tries, 1240 msec + * have passed in total, when poll + * returned the error, and 1200 msec + * when send returned the errors. */ +#ifndef USE_WINSOCK + pret = poll(NULL, 0, (SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); +#else + pret = WSAPoll(NULL, 0, (SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); +#endif + if(pret < 0 && +#ifndef USE_WINSOCK + errno != EAGAIN && errno != EINTR && +# ifdef EWOULDBLOCK + errno != EWOULDBLOCK && +# endif + errno != ENOBUFS +#else + WSAGetLastError() != WSAEINPROGRESS && + WSAGetLastError() != WSAEINTR && + WSAGetLastError() != WSAENOBUFS && + WSAGetLastError() != WSAEWOULDBLOCK +#endif + ) { + log_err("poll udp out timer failed: %s", + sock_strerror(errno)); + } } #endif /* defined(HAVE_POLL) || defined(USE_WINSOCK) */ + retries++; if (!is_connected) { sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), sldns_buffer_remaining(packet), 0, @@ -665,7 +715,8 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, WSAGetLastError() == WSAENOBUFS || WSAGetLastError() == WSAEWOULDBLOCK) { #endif - while(sent == -1 && ( + int retries = 0; + while(sent == -1 && retries < SEND_BLOCKED_MAX_RETRY && ( #ifndef USE_WINSOCK errno == EAGAIN || errno == EINTR || # ifdef EWOULDBLOCK @@ -680,6 +731,13 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, #endif )) { #if defined(HAVE_POLL) || defined(USE_WINSOCK) + int send_nobufs = ( +#ifndef USE_WINSOCK + errno == ENOBUFS +#else + WSAGetLastError() == WSAENOBUFS +#endif + ); struct pollfd p; int pret; memset(&p, 0, sizeof(p)); @@ -718,8 +776,48 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, log_err("poll udp out failed: %s", sock_strerror(errno)); return 0; + } else if((pret < 0 && +#ifndef USE_WINSOCK + errno == ENOBUFS +#else + WSAGetLastError() == WSAENOBUFS +#endif + ) || (send_nobufs && retries > 0)) { + /* ENOBUFS, and poll returned without + * a timeout. Or the retried send call + * returned ENOBUFS. It is good to + * wait a bit for the error to clear. */ + /* The timeout is 20*(2^(retries+1)), + * it increases exponentially, starting + * at 40 msec. After 5 tries, 1240 msec + * have passed in total, when poll + * returned the error, and 1200 msec + * when send returned the errors. */ +#ifndef USE_WINSOCK + pret = poll(NULL, 0, (SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); +#else + pret = WSAPoll(NULL, 0, (SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); +#endif + if(pret < 0 && +#ifndef USE_WINSOCK + errno != EAGAIN && errno != EINTR && +# ifdef EWOULDBLOCK + errno != EWOULDBLOCK && +# endif + errno != ENOBUFS +#else + WSAGetLastError() != WSAEINPROGRESS && + WSAGetLastError() != WSAEINTR && + WSAGetLastError() != WSAENOBUFS && + WSAGetLastError() != WSAEWOULDBLOCK +#endif + ) { + log_err("poll udp out timer failed: %s", + sock_strerror(errno)); + } } #endif /* defined(HAVE_POLL) || defined(USE_WINSOCK) */ + retries++; sent = sendmsg(c->fd, &msg, 0); } }