Blame SOURCES/0030-v2v-rhv-upload-plugin-Defer-imageio-connection.patch

62f9b7
From 987ddcd2ad7546212d3afed52b56f27a664624d6 Mon Sep 17 00:00:00 2001
62f9b7
From: Nir Soffer <nsoffer@redhat.com>
62f9b7
Date: Thu, 21 Jan 2021 03:40:00 +0200
62f9b7
Subject: [PATCH] v2v: rhv-upload-plugin: Defer imageio connection
62f9b7
62f9b7
When using vddk input with certain vmware version, qemu-img may spend
62f9b7
lot of time getting source image extents. If getting image extents takes
62f9b7
more than 60 seconds, imageio server closes the idle connection, and the
62f9b7
transfer will fail on the first write with:
62f9b7
62f9b7
nbdkit: python[1]: error: /var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py: pwrite: error:
62f9b7
Traceback (most recent call last):
62f9b7
   File "/var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py", line 94, in wrapper
62f9b7
    return func(h, *args)
62f9b7
   File "/var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py", line 230, in pwrite
62f9b7
    r = http.getresponse()
62f9b7
   File "/usr/lib64/python3.6/http/client.py", line 1361, in getresponse
62f9b7
    response.begin()
62f9b7
   File "/usr/lib64/python3.6/http/client.py", line 311, in begin
62f9b7
    version, status, reason = self._read_status()
62f9b7
   File "/usr/lib64/python3.6/http/client.py", line 280, in _read_status
62f9b7
    raise RemoteDisconnected("Remote end closed connection without"
62f9b7
 http.client.RemoteDisconnected: Remote end closed connection without response
62f9b7
62f9b7
This happens only when not using unix socket, for example when running
62f9b7
on non-ovirt host, or ovirt host from another data center, or when using
62f9b7
-oo rhv_direct=false
62f9b7
62f9b7
When using unix socket, we close the initial HTTPSConnection, and
62f9b7
created a new UnixHTTPConnection. This connection is not connected to
62f9b7
the server yet. When qemu-img tries to access the server, the connection
62f9b7
is connected automatically.
62f9b7
62f9b7
Fix the issue by closing the initial connection used to get server
62f9b7
options and initialize the handle, and storing a closed connection in
62f9b7
the handle.
62f9b7
62f9b7
Here is the flow with this change:
62f9b7
62f9b7
1. Create HTTPSConnection for getting server options
62f9b7
2. Close the connection[1]
62f9b7
3. If using unix socket, create UnixHTTPConnection.
62f9b7
4. Store the connection in the handle.
62f9b7
5. When qemu-img try to write/zero, the connection is reconnects
62f9b7
   automatically to imageio server[2]
62f9b7
62f9b7
Tested by adding a 300 milliseconds delay in nbdkit file plugin. Due to
62f9b7
the way qemu-img works, this cause more than 2 minutes delay after
62f9b7
open() but before the first pwrite(). Without this change, the import
62f9b7
fails consistently when using rhv_direct=false.
62f9b7
62f9b7
[1] https://github.com/python/cpython/blob/34df10a9a16b38d54421eeeaf73ec89828563be7/Lib/http/client.py#L958
62f9b7
[2] https://github.com/python/cpython/blob/34df10a9a16b38d54421eeeaf73ec89828563be7/Lib/http/client.py#L972
62f9b7
62f9b7
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
62f9b7
(cherry picked from commit 1d5fc257765c444644e5bfc6525e86ff201755f0)
62f9b7
---
62f9b7
 v2v/rhv-upload-plugin.py | 9 +++++++++
62f9b7
 1 file changed, 9 insertions(+)
62f9b7
62f9b7
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
62f9b7
index 471102da..7cd6dea6 100644
62f9b7
--- a/v2v/rhv-upload-plugin.py
62f9b7
+++ b/v2v/rhv-upload-plugin.py
62f9b7
@@ -117,6 +117,15 @@ def open(readonly):
62f9b7
         destination_url = parse_transfer_url(transfer)
62f9b7
         http = create_http(destination_url)
62f9b7
         options = get_options(http, destination_url)
62f9b7
+
62f9b7
+        # Close the initial connection to imageio server. When qemu-img will
62f9b7
+        # try to access the server, HTTPConnection will reconnect
62f9b7
+        # automatically. If we keep this connection idle and qemu-img is too
62f9b7
+        # slow getting image extents, imageio server may close the connection,
62f9b7
+        # and the import will fail on the first write.
62f9b7
+        # See https://bugzilla.redhat.com/1916176.
62f9b7
+        http.close()
62f9b7
+
62f9b7
         http = optimize_http(http, host, options)
62f9b7
     except:
62f9b7
         cancel_transfer(connection, transfer)