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

Timeout not working #1601

Open
basva923 opened this issue Aug 26, 2021 · 1 comment
Open

Timeout not working #1601

basva923 opened this issue Aug 26, 2021 · 1 comment

Comments

@basva923
Copy link

Timeout not working

Reproduce

  1. ManagementRoot(host, user, pwd, timeout=1)
  2. Timeout of 1 second is not respected

Problem

Timeout is not respected. Instead the default timeout for the 'request' library is used, which is forever.

Solution

Replace the following line:
response = connect.get(base_uri)
By:
response = connect.get(base_uri, timeout=self.args["timeout"])

Note: This will only fix the issue for the tmos version call, but since this is the first call the sqk always makes, it fixes the problem is most of the cases. If a connection opens ones, it will probably open a few seconds later.

More information

The timeout is supposed to be set here:
self.session.timeout = timeout
But that doesn't work anymore.

@HansAarneLiblik
Copy link

I solved this by wrapping ManagementRoot object and changinf icr_session

class WrappedManagementRoot(ManagementRoot):
    """A customized wrapper for f5.bigip.ManagementRoot providing preferred behavior."""

    def _get_icr_session(self, *args: Any, **kwargs: Any) -> iControlRESTSession:
        # We wrap this session creating to properly enforce timeouts
        icr_session: iControlRESTSession = super()._get_icr_session(*args, **kwargs)

        timeout: tuple[float, float] = (settings.F5_CONNECT_TIMEOUT, settings.READ_TIMEOUT)

        # noinspection HttpUrlsUsage
        icr_session.session.mount("http://", TimeoutHttpAdapter(timeout=timeout))
        icr_session.session.mount("https://", TimeoutHttpAdapter(timeout=timeout))

        return icr_session
        
 mgmt = WrappedManagementRoot(hostname, ....)       

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants