Browse Source

Merge #140: Alternative approach to connection reset.

76e4a7a Alternative approach to connection reset. (James Hilliard)
master
AdamISZ 8 years ago
parent
commit
622edaf523
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 20
      jmclient/jmclient/jsonrpc.py

20
jmclient/jmclient/jsonrpc.py

@ -20,10 +20,14 @@ from __future__ import absolute_import, print_function
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import errno
import socket
import base64
import httplib
import json
from jmclient import get_log
jlog = get_log()
class JsonRpcError(Exception):
"""
@ -100,13 +104,17 @@ class JsonRpc(object):
raise exc
except httplib.BadStatusLine:
return "CONNFAILURE"
except socket.error as e:
if e.errno != errno.ECONNRESET:
jlog.error('Unhandled connection error ' + str(e))
raise e
jlog.warn('Connection was reset, attempting reconnect.')
self.conn.close()
self.conn.connect()
continue
except Exception as exc:
if str(exc) == "Connection reset by peer":
self.conn.connect()
continue
else:
raise JsonRpcConnectionError("JSON-RPC connection failed. Err:" +
repr(exc))
raise JsonRpcConnectionError("JSON-RPC connection failed. Err:" +
repr(exc))
break
def call(self, method, params):

Loading…
Cancel
Save