All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: svt-core@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org
Subject: [PATCH hci-8.1 1/2] migration: fix source hang on cancel before the channel connects #VSTOR-155277
Date: Wed, 25 Nov 2026 20:32:03 +0100	[thread overview]
Message-ID: <20261125193204.1424799-2-den@openvz.org> (raw)
In-Reply-To: <20261125193204.1424799-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

Cancelling a migration while the source is still connecting to the
destination hangs the source QEMU forever if the connection then
succeeds. It hangs with the BQL held, so the monitor stops answering
too.

When the cancel arrives there is no connection yet and nothing to shut
down. Since c12736385bbc, migration_cancel() only marks the migration as
cancelling and leaves the rest to the code that runs when the connect
completes, and that code finishes the cancel only when the connect
fails.

When the connect succeeds, the migration starts anyway. The return path
thread starts and waits for the destination. The migration thread sees
the cancel and quits. The cleanup then waits for the return path thread
to exit, and that never happens: the destination has nothing to send
and keeps the connection open, and a cancel, unlike a failure, does not
make the cleanup shut the return path down.

Check for the cancel as soon as the connection is up, in
migration_channel_connect(), and clean up there before anything is
started. A cancel during the TLS handshake gets there too, once the
handshake is done. migration_cleanup() is no longer static so that
channel.c can call it.

Fixes: c12736385bbc ("migration: Fix crash on second migration when cancel early")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 migration/channel.c   | 6 ++++++
 migration/migration.c | 2 +-
 migration/migration.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/migration/channel.c b/migration/channel.c
index a547b1fbfeb..6016d6e47d8 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -73,6 +73,12 @@ void migration_channel_connect(MigrationState *s,
         ioc, object_get_typename(OBJECT(ioc)), hostname, error);
 
     if (!error) {
+        /* migration_cancel() leaves a cancel during connect for us to finish */
+        if (s->state == MIGRATION_STATUS_CANCELLING) {
+            migration_cleanup(s);
+            return;
+        }
+
         if (migrate_channel_requires_tls_upgrade(ioc)) {
             migration_tls_channel_connect(s, ioc, hostname, &error);
 
diff --git a/migration/migration.c b/migration/migration.c
index 57aa0dea264..8fcdf836ddc 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1493,7 +1493,7 @@ static void migration_cleanup_json_writer(MigrationState *s)
     g_clear_pointer(&s->vmdesc, json_writer_free);
 }
 
-static void migration_cleanup(MigrationState *s)
+void migration_cleanup(MigrationState *s)
 {
     MigrationEventType type;
     QEMUFile *tmp = NULL;
diff --git a/migration/migration.h b/migration/migration.h
index ee15ca88461..639474bfc2c 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -530,6 +530,7 @@ void migrate_set_error(MigrationState *s, const Error *error);
 bool migrate_has_error(MigrationState *s);
 
 void migration_connect(MigrationState *s, Error *error_in);
+void migration_cleanup(MigrationState *s);
 
 int migration_call_notifiers(MigrationEventType type, Error **errp);
 
-- 
2.55.0


  reply	other threads:[~2026-11-25 19:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a " Denis V. Lunev
2026-11-25 19:32 ` Denis V. Lunev [this message]
2026-12-01  0:30   ` [PATCH hci-8.1 1/2] migration: fix " no-reply
2026-11-25 19:32 ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " Denis V. Lunev
2026-12-01  0:31   ` no-reply
2026-11-25 20:14 ` [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Andrey Drobyshev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125193204.1424799-2-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.