From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 137E61FF15E for <inbox@lore.proxmox.com>; Tue, 8 Apr 2025 16:20:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 121651F4FD; Tue, 8 Apr 2025 16:20:19 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Tue, 8 Apr 2025 16:20:14 +0200 Message-Id: <20250408142014.86344-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250408142014.86344-1-f.ebner@proxmox.com> References: <20250408142014.86344-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.036 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH http-server 3/3] anyevent: handle 'disconnected' flag in client_do_disconnect() itself X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Commit f737984 ("fix #4816: do not disconnect twice if client sends no data") introduced a 'disconnected' flag in the request state to avoid duplicate calls to client_do_disconnect() for a given client. The flag is only set and checked in the on_error callback of the handle however. Do this more centrally at the beginning of the client_do_disconnect() function itself to catch all callers and code paths that could lead to a duplicate call. For example, while not currently known to cause issues, the on_eof handler might re-enter the function. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- src/PVE/APIServer/AnyEvent.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm index db14a7d..b71a9a5 100644 --- a/src/PVE/APIServer/AnyEvent.pm +++ b/src/PVE/APIServer/AnyEvent.pm @@ -136,6 +136,13 @@ sub cleanup_reqstate { sub client_do_disconnect { my ($self, $reqstate) = @_; + # Avoid any re-entrant call. For example, the on_error callback can be called twice for the same + # connection/handle if the timeout is reached before any data has been received. The on_error + # callback might also get invoked as part of the stoptls() call during shutdown below, which is + # another situation where the function would be re-entered without this check. + return if $reqstate->{disconnected}; + $reqstate->{disconnected} = 1; + cleanup_reqstate($reqstate, 1); my $shutdown_hdl = sub { @@ -1911,13 +1918,7 @@ sub accept_connections { my ($hdl, $fatal, $message) = @_; eval { $self->log_aborted_request($reqstate, $message); - # this error callback can be called twice for the same - # connection/handle if the timeout is reached before - # any data has been received, avoid misleading errors - if (!$reqstate->{disconnected}) { - $reqstate->{disconnected} = 1; - $self->client_do_disconnect($reqstate); - } + $self->client_do_disconnect($reqstate); }; if (my $err = $@) { syslog('err', "$err"); } }, -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel