From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH http-server 1/3] anyevent: disconnect: check that handle is still defined before calling shutdown()
Date: Tue, 8 Apr 2025 16:20:12 +0200 [thread overview]
Message-ID: <20250408142014.86344-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250408142014.86344-1-f.ebner@proxmox.com>
Commit 07e56cc ("fix unexpected EOF for client when closing TLS
session") added a call to stoptls() before the call to shutdown() for
the handle's file descriptor. However, the documentation for
AnyEvent[0] mentions for stoptls():
> This method may invoke callbacks (and therefore the handle might be
> destroyed after it returns).
Therefore, it is necessary to check that the handle is still defined
before calling shutdown(). Otherwise, this can result in a warning:
> Can't use an undefined value as a symbol reference at
> /usr/share/perl5/PVE/APIServer/AnyEvent.pm line 150.
as reported in the community forum [1].
The debug print message for closing the file handle is split up,
because part of it relies on the file handle to be defined.
[0]: https://metacpan.org/pod/AnyEvent::Handle#$handle-%3Estoptls
[1]: https://forum.proxmox.com/threads/164744/
Fixes: 07e56cc ("fix unexpected EOF for client when closing TLS session")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/APIServer/AnyEvent.pm | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 9b18ee2..3f8642b 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -146,8 +146,11 @@ sub client_do_disconnect {
$hdl->on_read(undef);
$hdl->on_eof(undef);
- $hdl->stoptls();
- shutdown($hdl->{fh}, 1);
+ $self->dprint("CLOSE FH" . $hdl->{fh}->fileno());
+
+ $hdl->stoptls(); # can invoke callbacks and destroy the handle
+
+ shutdown($hdl->{fh}, 1) if defined($hdl) && defined($hdl->{fh});
};
if (my $proxyhdl = delete $reqstate->{proxyhdl}) {
@@ -170,7 +173,7 @@ sub client_do_disconnect {
$self->{conn_count}--;
- $self->dprint("CLOSE FH" . $hdl->{fh}->fileno() . " CONN$self->{conn_count}");
+ $self->dprint("DISCONNECT CONN$self->{conn_count}");
}
sub finish_response {
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev 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 ` Fiona Ebner [this message]
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 ` [pve-devel] [PATCH http-server 3/3] anyevent: handle 'disconnected' flag in client_do_disconnect() itself Fiona Ebner
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-2-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