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

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