tests/qtest/vhost-user-test: Use g_timeout_add() to schedule connect
In vhost-user-test, we currently create a new g_thread to run the connect_thread() function. This function sleeps for 1 second, and then calls test_server_create_chr() to create and configure a chardev: chr = qemu_chr_new(server->chr_name, chr_path, server->context); g_assert(chr); qemu_chr_fe_init(&server->chr, chr, &error_abort); qemu_chr_fe_set_handlers(&server->chr, chr_can_read, chr_read, chr_event, NULL, server, server->context, true); This has a race condition, because when we set the 'reconnect-ms=1000' option on the chardev the socket chardev's implementation handles the connect asynchronously, via a background thread and a callback invoked in the main-loop thread. This means that that callback and the test_server_create_chr() call to qemu_chr_fe_set_handlers() can both enter the char-socket code simultaneously. The result is random assertion failures and memory leaks reported by the clang address-sanitizer. Fix this by using g_timeout_source_new() to set up a GSource that will run test_server_connect() on the main-loop thread. This ensures it can't execute in parallel with the callback that the socket chardev sets up. This is similar to how we already handle the reconnect_cb() in test_reconnect(). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de>