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.eb...@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

Reply via email to