From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 63E4C1FF0E1 for ; Mon, 16 Nov 2026 01:49:01 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6DAFA21718; Mon, 16 Nov 2026 01:48:30 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH container 23/34] migrate: remote: clean up the target on a tunnel version mismatch Date: Mon, 16 Nov 2026 01:46:35 +0100 Message-ID: <20261116004703.2908294-24-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261116004703.2908294-1-t.lamprecht@proxmox.com> References: <20261116004703.2908294-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794790030133 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.218 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: TTCSDAE3LPVYWKSRSXORNXBXQ7STRHKU X-Message-ID-Hash: TTCSDAE3LPVYWKSRSXORNXBXQ7STRHKU X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The target reserves the VMID with a locked config when it starts the tunnel worker, before the source compares the tunnel versions. On a mismatch the source failed without telling the target, so that config stayed behind and blocked the VMID there until an admin removed it. Ask the target to clean up before failing. If that fails too, log it and still report the version mismatch as the error. Signed-off-by: Thomas Lamprecht --- src/PVE/LXC/Migrate.pm | 12 +++++++++-- src/test/lifecycle_tests.pl | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm index d243d90..1882e57 100644 --- a/src/PVE/LXC/Migrate.pm +++ b/src/PVE/LXC/Migrate.pm @@ -147,11 +147,19 @@ sub prepare { $self->log('info', "local WS tunnel version: $WS_TUNNEL_VERSION"); $self->log('info', "remote WS tunnel version: $tunnel->{version}"); $self->log('info', "minimum required WS tunnel version: $min_version"); - die "Remote tunnel endpoint not compatible, upgrade required\n" + my $version_err; + $version_err = "Remote tunnel endpoint not compatible, upgrade required\n" if $WS_TUNNEL_VERSION < $min_version; - die "Remote tunnel endpoint too old, upgrade required\n" + $version_err = "Remote tunnel endpoint too old, upgrade required\n" if $WS_TUNNEL_VERSION > $tunnel->{version}; + if ($version_err) { + # the target already reserved the VMID with a locked config + eval { PVE::Tunnel::finish_tunnel($tunnel, 1); }; + $self->log('warn', "cleanup of the target failed - $@") if $@; + die $version_err; + } + $self->log('info', "websocket tunnel started\n"); $self->{tunnel} = $tunnel; } else { diff --git a/src/test/lifecycle_tests.pl b/src/test/lifecycle_tests.pl index d93f24e..e3a86a8 100755 --- a/src/test/lifecycle_tests.pl +++ b/src/test/lifecycle_tests.pl @@ -1549,6 +1549,49 @@ subtest 'restore over a container of another guest needs an override' => sub { $lxc_module->mock(delete_ifaces_ipams_ips => sub { }); }; +subtest 'remote migration cleans up a target with an incompatible tunnel version' => sub { + reset_configs(); + my $raw = existing_config('ctime=1500000000,rtime=1500000000000,uid=existingexistingexis'); + write_raw_config(200, $raw); + + my $log = ''; + my $migrate_module = Test::MockModule->new('PVE::AbstractMigrate'); + $migrate_module->mock(log => sub { $log .= "$_[1]: $_[2]\n" }); + + my $remote_version = { version => $PVE::LXC::Migrate::WS_TUNNEL_VERSION - 1, age => 0 }; + my ($commands, $cleanup) = (0); + my $tunnel_module = Test::MockModule->new('PVE::Tunnel'); + $tunnel_module->mock( + fork_websocket_tunnel => sub { return $remote_version }, + write_tunnel => sub { $commands++ }, + finish_tunnel => sub { (undef, $cleanup) = @_ }, + ); + + my $migrate = sub { + ($log, $commands, $cleanup) = ('', 0); + return run_task(sub { + PVE::LXC::Migrate->migrate( + 'remote-node', + '192.0.2.1', + 200, + { remote => { vmid => 300, conn => { host => '192.0.2.1', port => 8006 } } }, + ); + }); + }; + + like($migrate->(), qr/migration aborted/, 'migration to an older target fails'); + like($log, qr/^err: .*Remote tunnel endpoint too old/m, 'target is reported as too old'); + is($cleanup, 1, 'older target is asked to clean up'); + is($commands, 0, 'nothing else is sent to the target'); + is(read_raw_config(200), $raw, 'config of the source is unchanged'); + + $remote_version = { version => $PVE::LXC::Migrate::WS_TUNNEL_VERSION + 1, age => 0 }; + like($migrate->(), qr/migration aborted/, 'migration to an incompatible target fails'); + like($log, qr/^err: .*Remote tunnel endpoint not compatible/m, 'target is reported'); + is($cleanup, 1, 'incompatible target is asked to clean up'); + is(read_raw_config(200), $raw, 'config of the source is unchanged'); +}; + remove_tree($WORKDIR); done_testing(); -- 2.47.3