@@ -367,6 +367,7 @@ def execute_streaming(request, options: {}, &block)
367367 apply_auth ( request , basic_auth ) if redirects . zero?
368368
369369 # don't call return within the `request` block
370+ close_and_sleep = nil
370371 http . request ( request ) do |nethttp |
371372 response = Puppet ::HTTP ::ResponseNetHTTP . new ( request . uri , nethttp )
372373 begin
@@ -380,12 +381,14 @@ def execute_streaming(request, options: {}, &block)
380381 interval = @retry_after_handler . retry_after_interval ( request , response , retries )
381382 retries += 1
382383 if interval
383- if http . started?
384- Puppet . debug ( "Closing connection for #{ Puppet ::HTTP ::Site . from_uri ( request . uri ) } " )
385- http . finish
384+ close_and_sleep = proc do
385+ if http . started?
386+ Puppet . debug ( "Closing connection for #{ Puppet ::HTTP ::Site . from_uri ( request . uri ) } " )
387+ http . finish
388+ end
389+ Puppet . warning ( _ ( "Sleeping for %{interval} seconds before retrying the request" ) % { interval : interval } )
390+ ::Kernel . sleep ( interval )
386391 end
387- Puppet . warning ( _ ( "Sleeping for %{interval} seconds before retrying the request" ) % { interval : interval } )
388- ::Kernel . sleep ( interval )
389392 next
390393 end
391394 end
@@ -404,6 +407,10 @@ def execute_streaming(request, options: {}, &block)
404407
405408 done = true
406409 end
410+ ensure
411+ # If a server responded with a retry, make sure the connection is closed and then
412+ # sleep the specified time.
413+ close_and_sleep . call if close_and_sleep
407414 end
408415 end
409416
0 commit comments