Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added api connection_timeout to recover from lost connections #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions matrix_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class MatrixHttpApi(object):
def __init__(
self, base_url, token=None, identity=None,
default_429_wait_ms=5000,
use_authorization_header=True
use_authorization_header=True,
connection_timeout=60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docstring

):
try:
scheme, auth, host, port, path, query, fragment = parse_url(base_url)
Expand All @@ -74,6 +75,7 @@ def __init__(
self.session = Session()
self.default_429_wait_ms = default_429_wait_ms
self.use_authorization_header = use_authorization_header
self.connection_timeout = connection_timeout

def initial_sync(self, limit=1):
"""
Expand Down Expand Up @@ -725,7 +727,8 @@ def _send(self, method, path, content=None, query_params=None, headers=None,
params=query_params,
data=content,
headers=headers,
verify=self.validate_cert
verify=self.validate_cert,
timeout=self.connection_timeout,
)
except RequestException as e:
raise MatrixHttpLibError(e, method, endpoint)
Expand Down
6 changes: 4 additions & 2 deletions matrix_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def global_callback(incoming_event):

def __init__(self, base_url, token=None, user_id=None,
valid_cert_check=True, sync_filter_limit=20,
cache_level=CACHE.ALL, encryption=False, encryption_conf=None):
cache_level=CACHE.ALL, encryption=False, encryption_conf=None,
api_connection_timeout=60):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just call this timeout instead of connection_timeout or api_connection_timeout for conciseness?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docstring.

if user_id:
warn(
"user_id is deprecated. "
Expand All @@ -122,7 +123,8 @@ def __init__(self, base_url, token=None, user_id=None,
raise ValueError("Failed to enable encryption. Please make sure the olm "
"library is available.")

self.api = MatrixHttpApi(base_url, token)
self.api = MatrixHttpApi(base_url, token,
connection_timeout=api_connection_timeout)
self.api.validate_certificate(valid_cert_check)
self.listeners = []
self.presence_listeners = {}
Expand Down