Skip to content

Commit

Permalink
v2v: rhv-upload-plugin: Defer imageio connection
Browse files Browse the repository at this point in the history
When using vddk input with certain vmware version, qemu-img may spend
lot of time getting source image extents. If getting image extents takes
more than 60 seconds, imageio server closes the idle connection, and the
transfer will fail on the first write with:

nbdkit: python[1]: error: /var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py: pwrite: error:
Traceback (most recent call last):
   File "/var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py", line 94, in wrapper
    return func(h, *args)
   File "/var/tmp/rhvupload.0OKqWA/rhv-upload-plugin.py", line 230, in pwrite
    r = http.getresponse()
   File "/usr/lib64/python3.6/http/client.py", line 1361, in getresponse
    response.begin()
   File "/usr/lib64/python3.6/http/client.py", line 311, in begin
    version, status, reason = self._read_status()
   File "/usr/lib64/python3.6/http/client.py", line 280, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
 http.client.RemoteDisconnected: Remote end closed connection without response

This happens only when not using unix socket, for example when running
on non-ovirt host, or ovirt host from another data center, or when using
-oo rhv_direct=false

When using unix socket, we close the initial HTTPSConnection, and
created a new UnixHTTPConnection. This connection is not connected to
the server yet. When qemu-img tries to access the server, the connection
is connected automatically.

Fix the issue by closing the initial connection used to get server
options and initialize the handle, and storing a closed connection in
the handle.

Here is the flow with this change:

1. Create HTTPSConnection for getting server options
2. Close the connection[1]
3. If using unix socket, create UnixHTTPConnection.
4. Store the connection in the handle.
5. When qemu-img try to write/zero, the connection is reconnects
   automatically to imageio server[2]

Tested by adding a 300 milliseconds delay in nbdkit file plugin. Due to
the way qemu-img works, this cause more than 2 minutes delay after
open() but before the first pwrite(). Without this change, the import
fails consistently when using rhv_direct=false.

[1] https://github.com/python/cpython/blob/34df10a9a16b38d54421eeeaf73ec89828563be7/Lib/http/client.py#L958
[2] https://github.com/python/cpython/blob/34df10a9a16b38d54421eeeaf73ec89828563be7/Lib/http/client.py#L972

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jan 21, 2021
1 parent 899d784 commit 1d5fc25
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions v2v/rhv-upload-plugin.py
Expand Up @@ -117,6 +117,15 @@ def open(readonly):
destination_url = parse_transfer_url(transfer)
http = create_http(destination_url)
options = get_options(http, destination_url)

# Close the initial connection to imageio server. When qemu-img will
# try to access the server, HTTPConnection will reconnect
# automatically. If we keep this connection idle and qemu-img is too
# slow getting image extents, imageio server may close the connection,
# and the import will fail on the first write.
# See https://bugzilla.redhat.com/1916176.
http.close()

http = optimize_http(http, host, options)
except:
cancel_transfer(connection, transfer)
Expand Down

0 comments on commit 1d5fc25

Please sign in to comment.