From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, "Peter Xu" <peterx@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH 1/2] migration: fix source hang on cancel before the channel connects
Date: Wed, 25 Nov 2026 20:31:01 +0100 [thread overview]
Message-ID: <20261125193102.1423555-2-den@openvz.org> (raw)
In-Reply-To: <20261125193102.1423555-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 4f08b870f8fd, 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_outgoing(), 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: 4f08b870f8fd ("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 1aeb881485..6e2bf9ad39 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -563,6 +563,12 @@ void migration_channel_connect_outgoing(MigrationState *s, QIOChannel *ioc)
{
trace_migration_outgoing_channel_set(ioc, object_get_typename(OBJECT(ioc)));
+ /* 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)) {
Error *local_err = NULL;
diff --git a/migration/migration.c b/migration/migration.c
index 5686209ab1..4fc1ca9fd2 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1378,7 +1378,7 @@ 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)
{
QEMUFile *tmp = NULL;
diff --git a/migration/migration.h b/migration/migration.h
index 057c85d611..b3067536cb 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -594,6 +594,7 @@ bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **errp);
void migration_outgoing_setup(QIOChannel *ioc);
void migration_connect_error_propagate(MigrationState *s, Error *error);
+void migration_cleanup(MigrationState *s);
void migrate_error_propagate(MigrationState *s, Error *error);
bool migrate_has_error(MigrationState *s);
--
2.55.0
next prev parent reply other threads:[~2026-11-25 19:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 19:31 [PATCH 0/2] migration: fix a source hang on cancel before the channel connects Denis V. Lunev
2026-11-25 19:31 ` Denis V. Lunev [this message]
2026-11-25 19:31 ` [PATCH 2/2] tests/qtest/migration: test " Denis V. Lunev
2026-11-26 19:33 ` Peter Xu
2026-11-25 23:26 ` [PATCH 0/2] migration: fix a source hang on " Fabiano Rosas
2026-11-26 14:02 ` Denis V. Lunev
2026-11-26 14:38 ` Fabiano Rosas
2026-11-26 19:32 ` Peter Xu
2026-11-26 19:39 ` Peter Xu
2026-11-26 21:20 ` Fabiano Rosas
2026-11-27 12:22 ` Peter Xu
2026-11-27 12:49 ` Fabiano Rosas
2026-11-27 13:28 ` Peter Xu
2026-11-27 14:21 ` Fabiano Rosas
2026-11-27 14:59 ` Peter Xu
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=20261125193102.1423555-2-den@openvz.org \
--to=den@openvz.org \
--cc=farosas@suse.de \
--cc=marcandre.lureau@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.