[pve-devel] [PATCH pve-client 3/7] lxc console: limit output buffer size

Dietmar Maurer dietmar at proxmox.com
Fri Jun 8 11:25:53 CEST 2018


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/APIClient/Commands/lxc.pm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index 979b580..620e4b1 100644
--- a/PVE/APIClient/Commands/lxc.pm
+++ b/PVE/APIClient/Commands/lxc.pm
@@ -281,6 +281,8 @@ __PACKAGE__->register_method ({
 		$winch_received = 0;
 	    };
 
+	    my $max_buffer_len = 256*1024;
+
 	    my $drain_buffer = sub {
 		my ($fh, $buffer_ref) = @_;
 
@@ -292,7 +294,8 @@ __PACKAGE__->register_method ({
 		}
 		return $nr if !$nr;
 		substr($$buffer_ref, 0, $nr, '');
-		$write_select->remove($fh) if !length($$buffer_ref);
+		$len = length($$buffer_ref);
+		$write_select->remove($fh) if !$len;
 	    };
 
 	    while (1) {
@@ -302,6 +305,7 @@ __PACKAGE__->register_method ({
 		    foreach my $fh (@$writable) {
 			if ($fh == $output_fh) {
 			    $drain_buffer->(\*STDOUT, \$output_buffer);
+			    $read_select->add($web_socket) if length($output_buffer) <= $max_buffer_len;
 			} elsif ($fh == $web_socket) {
 			    $drain_buffer->($web_socket, \$websock_buffer);
 			}
@@ -319,9 +323,12 @@ __PACKAGE__->register_method ({
 				return; # EOF
 			    } else {
 				my ($payload, $req_close) = $parse_web_socket_frame->(\$wsbuf);
-				if ($payload) {
+				if (defined($payload) && length($payload)) {
 				    $output_buffer .= $payload;
 				    $write_select->add($output_fh);
+				    if (length($output_buffer) > $max_buffer_len) {
+					$read_select->remove($web_socket);
+				    }
 				}
 				return if $req_close;
 			    }
-- 
2.11.0




More information about the pve-devel mailing list