Skip to content

Commit

Permalink
Overcome "Connection Refused" on some operations
Browse files Browse the repository at this point in the history
So some operations on Windows actually cause the WinRM service to become
unavailable for some time and WinRM currently cannot overcome this
problem. Since this is a real problem to us when e.g. installing SCVMM
on servers and we cannot influence the installer, here is the
work-around we implemented.

The current implementation simply tries 5 times with a 5 seconds delay,
but YMMV. Ideally this is configurable by the user, and future defaults
should be tested.
  • Loading branch information
dagwieers committed Aug 20, 2017
1 parent b1a54bc commit 272716a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion winrm/transport.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import unicode_literals
from contextlib import contextmanager
import errno
import re
import sys
import os
import time
import weakref

is_py2 = sys.version[0] == '2'
Expand Down Expand Up @@ -189,7 +191,18 @@ def send_message(self, message):
prepared_request = self.session.prepare_request(request)

try:
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)

for retry in range(5):
try:
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)
break
except requests.exceptions.ConnectionError as e:
if e.args[0].reason.errno != errno.ECONNREFUSED:
raise
if retry == 4:
raise
time.sleep(5)

response_text = response.text
response.raise_for_status()
return response_text
Expand Down

0 comments on commit 272716a

Please sign in to comment.