public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH] systemd: disconnect signals
@ 2025-03-03 14:42 Maximiliano Sandoval
  2025-03-06 15:54 ` Wolfgang Bumiller
  0 siblings, 1 reply; 3+ messages in thread
From: Maximiliano Sandoval @ 2025-03-03 14:42 UTC (permalink / raw)
  To: pve-devel

Dbus has a limit of 512 connections by default and signals should be
disconnected as soon as they are not needed anymore.

This should alleviate https://bugzilla.proxmox.com/show_bug.cgi?id=5876.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 src/PVE/Systemd.pm | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
index 07c912e3..1d7772d9 100644
--- a/src/PVE/Systemd.pm
+++ b/src/PVE/Systemd.pm
@@ -44,6 +44,7 @@ sub unescape_unit {
 # main loop is being used as we need to wait signals.
 sub systemd_call($;$) {
     my ($code, $timeout) = @_;
+    my $signal_info;
 
     my $bus = Net::DBus->system();
     my $reactor = Net::DBus::Reactor->main();
@@ -64,13 +65,22 @@ sub systemd_call($;$) {
 	    $timer = undef;
 	}
 
+	if (defined($signal_info)) {
+	    if (my $signal_name = $signal_info->{name}) {
+		if (my $signal_handle = $signal_info->{handle}) {
+		    $if->disconnect_from_signal($signal_name, $signal_handle);
+		}
+	    }
+	    $signal_info = undef;
+	}
+
 	if (defined($reactor)) {
 	    $reactor->shutdown();
 	    $reactor = undef;
 	}
     };
 
-    my $result = $code->($if, $reactor, $finish_callback);
+    (my $result, $signal_info) = $code->($if, $reactor, $finish_callback);
     # Are we done immediately?
     return $result if defined $result;
 
@@ -124,7 +134,8 @@ sub enter_systemd_scope {
 
 	my $job;
 
-	$if->connect_to_signal('JobRemoved', sub {
+	my $signal_name = 'JobRemoved';
+	my $signal_handle = $if->connect_to_signal($signal_name, sub {
 	    my ($id, $removed_job, $signaled_unit, $result) = @_;
 	    return if $signaled_unit ne $unit || $removed_job ne $job;
 	    if ($result ne 'done') {
@@ -139,7 +150,12 @@ sub enter_systemd_scope {
 
 	$job = $if->StartTransientUnit($unit, 'fail', $properties, []);
 
-	return undef;
+	my $signal_info = {
+	    name => $signal_name,
+	    handle => $signal_handle,
+	};
+
+	return (undef, $signal_info);
     }, $timeout);
 }
 
@@ -152,18 +168,24 @@ sub wait_for_unit_removed($;$) {
 	my $unit_obj = eval { $if->GetUnit($unit) };
 	return 1 if !$unit_obj;
 
-	$if->connect_to_signal('UnitRemoved', sub {
+	my $signal_name = 'UnitRemoved';
+	my $signal_handle = $if->connect_to_signal($signal_name, sub {
 	    my ($id, $removed_unit) = @_;
 	    $finish_cb->(1) if $removed_unit eq $unit_obj;
 	});
 
+	my $signal_info = {
+	    name => $signal_name,
+	    handle => $signal_handle,
+	};
+
 	# Deal with what we lost between GetUnit() and connecting to UnitRemoved:
 	my $unit_obj_new = eval { $if->GetUnit($unit) };
 	if (!$unit_obj_new) {
-	    return 1;
+	    return (1, $signal_info);
 	}
 
-	return undef;
+	return (undef, $signal_info);
     }, $timeout);
 }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH] systemd: disconnect signals
  2025-03-03 14:42 [pve-devel] [PATCH] systemd: disconnect signals Maximiliano Sandoval
@ 2025-03-06 15:54 ` Wolfgang Bumiller
  2025-03-07  8:14   ` Maximiliano Sandoval
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Bumiller @ 2025-03-06 15:54 UTC (permalink / raw)
  To: Maximiliano Sandoval; +Cc: pve-devel

On Mon, Mar 03, 2025 at 03:42:53PM +0100, Maximiliano Sandoval wrote:
> Dbus has a limit of 512 connections by default and signals should be
> disconnected as soon as they are not needed anymore.
> 
> This should alleviate https://bugzilla.proxmox.com/show_bug.cgi?id=5876.
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>  src/PVE/Systemd.pm | 34 ++++++++++++++++++++++++++++------
>  1 file changed, 28 insertions(+), 6 deletions(-)
> 
> diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
> index 07c912e3..1d7772d9 100644
> --- a/src/PVE/Systemd.pm
> +++ b/src/PVE/Systemd.pm
> @@ -44,6 +44,7 @@ sub unescape_unit {
>  # main loop is being used as we need to wait signals.
>  sub systemd_call($;$) {
>      my ($code, $timeout) = @_;
> +    my $signal_info;
>  
>      my $bus = Net::DBus->system();
>      my $reactor = Net::DBus::Reactor->main();
> @@ -64,13 +65,22 @@ sub systemd_call($;$) {
>  	    $timer = undef;
>  	}
>  
> +	if (defined($signal_info)) {
> +	    if (my $signal_name = $signal_info->{name}) {
> +		if (my $signal_handle = $signal_info->{handle}) {

I think it's enough to require the info to either be valid or undef,
therefore the first `if` should suffice.

> +		    $if->disconnect_from_signal($signal_name, $signal_handle);
> +		}
> +	    }
> +	    $signal_info = undef;
> +	}
> +
>  	if (defined($reactor)) {
>  	    $reactor->shutdown();
>  	    $reactor = undef;
>  	}
>      };
>  
> -    my $result = $code->($if, $reactor, $finish_callback);
> +    (my $result, $signal_info) = $code->($if, $reactor, $finish_callback);
>      # Are we done immediately?
>      return $result if defined $result;
>  
> @@ -124,7 +134,8 @@ sub enter_systemd_scope {
>  
>  	my $job;
>  
> -	$if->connect_to_signal('JobRemoved', sub {
> +	my $signal_name = 'JobRemoved';
> +	my $signal_handle = $if->connect_to_signal($signal_name, sub {
>  	    my ($id, $removed_job, $signaled_unit, $result) = @_;
>  	    return if $signaled_unit ne $unit || $removed_job ne $job;
>  	    if ($result ne 'done') {
> @@ -139,7 +150,12 @@ sub enter_systemd_scope {
>  
>  	$job = $if->StartTransientUnit($unit, 'fail', $properties, []);
>  
> -	return undef;
> +	my $signal_info = {
> +	    name => $signal_name,
> +	    handle => $signal_handle,
> +	};
> +
> +	return (undef, $signal_info);
>      }, $timeout);
>  }
>  
> @@ -152,18 +168,24 @@ sub wait_for_unit_removed($;$) {
>  	my $unit_obj = eval { $if->GetUnit($unit) };
>  	return 1 if !$unit_obj;
>  
> -	$if->connect_to_signal('UnitRemoved', sub {
> +	my $signal_name = 'UnitRemoved';
> +	my $signal_handle = $if->connect_to_signal($signal_name, sub {
>  	    my ($id, $removed_unit) = @_;
>  	    $finish_cb->(1) if $removed_unit eq $unit_obj;
>  	});
>  
> +	my $signal_info = {
> +	    name => $signal_name,
> +	    handle => $signal_handle,
> +	};
> +
>  	# Deal with what we lost between GetUnit() and connecting to UnitRemoved:
>  	my $unit_obj_new = eval { $if->GetUnit($unit) };
>  	if (!$unit_obj_new) {
> -	    return 1;
> +	    return (1, $signal_info);
>  	}
>  
> -	return undef;
> +	return (undef, $signal_info);
>      }, $timeout);
>  }
>  
> -- 
> 2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH] systemd: disconnect signals
  2025-03-06 15:54 ` Wolfgang Bumiller
@ 2025-03-07  8:14   ` Maximiliano Sandoval
  0 siblings, 0 replies; 3+ messages in thread
From: Maximiliano Sandoval @ 2025-03-07  8:14 UTC (permalink / raw)
  To: Wolfgang Bumiller; +Cc: pve-devel


Wolfgang Bumiller <w.bumiller@proxmox.com> writes:

> On Mon, Mar 03, 2025 at 03:42:53PM +0100, Maximiliano Sandoval wrote:
>> Dbus has a limit of 512 connections by default and signals should be
>> disconnected as soon as they are not needed anymore.
>>
>> This should alleviate https://bugzilla.proxmox.com/show_bug.cgi?id=5876.
>>
>> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
>> ---
>>  src/PVE/Systemd.pm | 34 ++++++++++++++++++++++++++++------
>>  1 file changed, 28 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
>> index 07c912e3..1d7772d9 100644
>> --- a/src/PVE/Systemd.pm
>> +++ b/src/PVE/Systemd.pm
>> @@ -44,6 +44,7 @@ sub unescape_unit {
>>  # main loop is being used as we need to wait signals.
>>  sub systemd_call($;$) {
>>      my ($code, $timeout) = @_;
>> +    my $signal_info;
>>
>>      my $bus = Net::DBus->system();
>>      my $reactor = Net::DBus::Reactor->main();
>> @@ -64,13 +65,22 @@ sub systemd_call($;$) {
>>  	    $timer = undef;
>>  	}
>>
>> +	if (defined($signal_info)) {
>> +	    if (my $signal_name = $signal_info->{name}) {
>> +		if (my $signal_handle = $signal_info->{handle}) {
>
> I think it's enough to require the info to either be valid or undef,
> therefore the first `if` should suffice.
>
>> +		    $if->disconnect_from_signal($signal_name, $signal_handle);
>> +		}
>> +	    }
>> +	    $signal_info = undef;
>> +	}
>> +
>>  	if (defined($reactor)) {
>>  	    $reactor->shutdown();
>>  	    $reactor = undef;
>>  	}
>>      };
>>
>> -    my $result = $code->($if, $reactor, $finish_callback);
>> +    (my $result, $signal_info) = $code->($if, $reactor, $finish_callback);
>>      # Are we done immediately?
>>      return $result if defined $result;
>>
>> @@ -124,7 +134,8 @@ sub enter_systemd_scope {
>>
>>  	my $job;
>>
>> -	$if->connect_to_signal('JobRemoved', sub {
>> +	my $signal_name = 'JobRemoved';
>> +	my $signal_handle = $if->connect_to_signal($signal_name, sub {
>>  	    my ($id, $removed_job, $signaled_unit, $result) = @_;
>>  	    return if $signaled_unit ne $unit || $removed_job ne $job;
>>  	    if ($result ne 'done') {
>> @@ -139,7 +150,12 @@ sub enter_systemd_scope {
>>
>>  	$job = $if->StartTransientUnit($unit, 'fail', $properties, []);
>>
>> -	return undef;
>> +	my $signal_info = {
>> +	    name => $signal_name,
>> +	    handle => $signal_handle,
>> +	};
>> +
>> +	return (undef, $signal_info);
>>      }, $timeout);
>>  }
>>
>> @@ -152,18 +168,24 @@ sub wait_for_unit_removed($;$) {
>>  	my $unit_obj = eval { $if->GetUnit($unit) };
>>  	return 1 if !$unit_obj;
>>
>> -	$if->connect_to_signal('UnitRemoved', sub {
>> +	my $signal_name = 'UnitRemoved';
>> +	my $signal_handle = $if->connect_to_signal($signal_name, sub {
>>  	    my ($id, $removed_unit) = @_;
>>  	    $finish_cb->(1) if $removed_unit eq $unit_obj;
>>  	});
>>
>> +	my $signal_info = {
>> +	    name => $signal_name,
>> +	    handle => $signal_handle,
>> +	};
>> +
>>  	# Deal with what we lost between GetUnit() and connecting to UnitRemoved:
>>  	my $unit_obj_new = eval { $if->GetUnit($unit) };
>>  	if (!$unit_obj_new) {
>> -	    return 1;
>> +	    return (1, $signal_info);
>>  	}
>>
>> -	return undef;
>> +	return (undef, $signal_info);
>>      }, $timeout);
>>  }
>>
>> --
>> 2.39.5

v2 sent.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-07  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03 14:42 [pve-devel] [PATCH] systemd: disconnect signals Maximiliano Sandoval
2025-03-06 15:54 ` Wolfgang Bumiller
2025-03-07  8:14   ` Maximiliano Sandoval

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