[pve-devel] [PATCH http-server 1/3] anyevent: disconnect: check that handle is still defined before calling shutdown()
Fiona Ebner
f.ebner at proxmox.com
Tue Apr 8 16:20:12 CEST 2025
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 at 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
More information about the pve-devel
mailing list