@@ -257,27 +257,31 @@ let remote_metadata_export_import ~__context ~rpc ~session_id ~remote_address ~r
257257 ] ~keep_alive: false
258258 Http. Put remote_import_request in
259259 debug " Piping HTTP %s to %s" (Http.Request. to_string get) (Http.Request. to_string put);
260- with_transport (Unix Xapi_globs. unix_domain_socket)
261- (with_http get
262- (fun (r , ifd ) ->
263- debug " Content-length: %s" (Stdext.Opt. default " None" (Stdext.Opt. map Int64. to_string r.Http.Response. content_length));
264- let put = { put with Http.Request. content_length = r.Http.Response. content_length } in
265- debug " Connecting to %s:%d" remote_address ! Xapi_globs. https_port;
266- (* Spawn a cached stunnel instance. Otherwise, once metadata tranmission completes, the connection
267- between local xapi and stunnel will be closed immediately, and the new spawned stunnel instance
268- will be revoked, this might cause the remote stunnel gets partial metadata xml file, and the
269- ripple effect is that remote xapi fails to parse metadata xml file. Using a cached stunnel can
270- not always avoid the problem since any cached stunnel entry might be evicted. However, it is
271- unlikely to happen in practice because the cache size is large enough.*)
272- with_transport (SSL (SSL. make ~use_stunnel_cache: true () , remote_address, ! Xapi_globs. https_port))
273- (with_http put
274- (fun (_ , ofd ) ->
260+ begin try
261+ with_transport (Unix Xapi_globs. unix_domain_socket)
262+ (with_http get
263+ (fun (r , ifd ) ->
264+ debug " Content-length: %s" (Stdext.Opt. default " None" (Stdext.Opt. map Int64. to_string r.Http.Response. content_length));
265+ let put = { put with Http.Request. content_length = r.Http.Response. content_length } in
266+ debug " Connecting to %s:%d" remote_address ! Xapi_globs. https_port;
267+ (* Spawn a cached stunnel instance. Otherwise, once metadata tranmission completes, the connection
268+ between local xapi and stunnel will be closed immediately, and the new spawned stunnel instance
269+ will be revoked, this might cause the remote stunnel gets partial metadata xml file, and the
270+ ripple effect is that remote xapi fails to parse metadata xml file. Using a cached stunnel can
271+ not always avoid the problem since any cached stunnel entry might be evicted. However, it is
272+ unlikely to happen in practice because the cache size is large enough.*)
273+ with_transport (SSL (SSL. make ~use_stunnel_cache: true () , remote_address, ! Xapi_globs. https_port))
274+ (with_http put
275+ (fun (_ , ofd ) ->
275276 let (n: int64 ) = Stdext.Unixext. copy_file ?limit:r.Http.Response. content_length ifd ofd in
276277 debug " Written %Ld bytes" n
277- )
278- )
279- )
280- );
278+ )
279+ )
280+ )
281+ )
282+ with Xmlrpc_client. Stunnel_connection_failed ->
283+ raise (Api_errors. Server_error (Api_errors. tls_connection_failed, [remote_address; (string_of_int ! Xapi_globs. https_port)]))
284+ end ;
281285 (* Wait for remote task to succeed or fail *)
282286 Cli_util. wait_for_task_completion rpc session_id remote_task;
283287 match Client.Task. get_status rpc session_id remote_task with
0 commit comments