public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH http-server 3/3] anyevent: handle 'disconnected' flag in client_do_disconnect() itself
Date: Tue,  8 Apr 2025 16:20:14 +0200	[thread overview]
Message-ID: <20250408142014.86344-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250408142014.86344-1-f.ebner@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


  parent reply	other threads:[~2025-04-08 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 14:20 [pve-devel] [PATCH-SERIES http-server 0/3] fix disconnecting clients Fiona Ebner
2025-04-08 14:20 ` [pve-devel] [PATCH http-server 1/3] anyevent: disconnect: check that handle is still defined before calling shutdown() Fiona Ebner
2025-04-08 14:20 ` [pve-devel] [PATCH http-server 2/3] anyevent: always avoid re-entering client_do_disconnect() in on_error callback Fiona Ebner
2025-04-08 14:20 ` Fiona Ebner [this message]
2025-04-08 14:51 ` [pve-devel] [PATCH-SERIES http-server 0/3] fix disconnecting clients Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250408142014.86344-4-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal