Skip to content

Commit

Permalink
Merge pull request #130 from isi-adas/BR_PSCALE_176731
Browse files Browse the repository at this point in the history
Changes in connect function
  • Loading branch information
masenf authored Apr 28, 2023
2 parents 5b9668f + e3d6a85 commit 44475ff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
'test',
'transport',
]
__version_info__ = (0, 2, 27)
__version_info__ = (0, 2, 28)
__version__ = "{0}.{1}.{2}".format(*__version_info__)
13 changes: 11 additions & 2 deletions pike/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import time
import operator
import contextlib
import polling2

import auth
import core
Expand Down Expand Up @@ -329,7 +330,7 @@ def unregister_callback(self, event, cb):
return
self.callbacks[ev].remove(cb)

def connect(self, server, port=445):
def connect(self, server, port=445, max_tries=2):
"""
Create a connection.
Expand All @@ -338,7 +339,15 @@ def connect(self, server, port=445):
@param server: The server to connect to.
@param port: The port to connect to.
"""
return self.connect_submit(server, port).result()
# Setting connection timeout to TCP default i.e. 120 secs
conn = polling2.poll(
lambda: self.connect_submit(server, port).result(timeout=default_timeout * 4),
ignore_exceptions=(ResponseError, TimeoutError,),
step=30,
max_tries=max_tries,
)
return conn


def connect_submit(self, server, port=445):
"""
Expand Down
4 changes: 2 additions & 2 deletions pike/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def set_client_dialect(self, min_dialect=None, max_dialect=None,
client.dialects = filter(
lambda d: d <= max_dialect, client.dialects)

def tree_connect(self, client=None, resume=None):
def tree_connect(self, client=None, resume=None, max_tries=2):
dialect_range = self.required_dialect()
req_caps = self.required_capabilities()
req_share_caps = self.required_share_capabilities()

if client is None:
client = self.default_client

conn = client.connect(self.server, self.port).negotiate()
conn = client.connect(self.server, self.port, max_tries=max_tries).negotiate()

if (conn.negotiate_response.dialect_revision < dialect_range[0] or
conn.negotiate_response.dialect_revision > dialect_range[1]):
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def run_setup(with_extensions):
author_email='[email protected]',
url='https://github.com/emc-isilon/pike',
packages=['pike', 'pike.test'],
install_requires=['pycryptodomex'],
install_requires=[
'pycryptodomex',
'polling2'
],
ext_modules=ext_modules,
test_suite='setup.pike_suite',
cmdclass=cmdclass,
Expand Down

0 comments on commit 44475ff

Please sign in to comment.