8000 Only 2 Secound Timout for Rest Calls · Issue #353 · jython/jython · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Only 2 Secound Timout for Rest Calls #353

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

Open
paz0ok opened this issue Aug 20, 2024 · 1 comment
Open

Only 2 Secound Timout for Rest Calls #353

paz0ok opened this issue Aug 20, 2024 · 1 comment

Comments

@paz0ok
Copy link
paz0ok commented Aug 20, 2024

Hi everyone,

I have an issue with the timeout for rest calls.
The issue I'm having is in Lib/_socket.py 858 (_handle_timeout).
The tool I'm using is running Python 2 and has a max int of 2147483647. This will give me only 2.14 seconds of timeout.
If I give the int() function more than the max int it will be automatically reduced.
Does anyone have a solution that can be implemented in the Jython repo?

Here a screenshot from the tool:
image

Thanks :)

@Andrysqui
Copy link

I've been checking how to make the maximum number for the timeout larger.

One way could be to in this line of the function:

timeout_in_ns = int(self.timeout * _TO_NANOSECONDS)

Use long instead of int so that the value for the timeout isn't reduced:

timeout_in_ns = long(self.timeout * _TO_NANOSECONDS)

So now the function would look like:

def _handle_timeout(self, waiter, reason):
    timeout_in_ns = long(self.timeout * _TO_NANOSECONDS)  # Switch to 'long' for larger timeouts
    log.debug("Waiting for up to %.2fs for %s", self.timeout, reason, extra={"sock": self})
    
    started = time.time()
    result = waiter(timeout_in_ns, TimeUnit.NANOSECONDS)
    
    log.debug("Completed in %.2fs", time.time() - started, extra={"sock": self})
    
    if not result:
        if self.timeout == 0:
            raise error(errno.ETIMEDOUT, "Connection timed out")
        else:
            raise timeout(errno.ETIMEDOUT, "timed out")
    
    return result

This would increase the limit for the timeout to pretty much infinity as much as your device has enough memory, or the number isn't big enough to cause any issues with the library or Jython in general.

Maybe it could be a good idea to add something like a limit to make it more difficult for something to end up breaking:

def _handle_timeout(self, waiter, reason):
    timeout_in_ns = long(self.timeout * _TO_NANOSECONDS)  # Use 'long' for larger timeouts
    max_timeout_in_ns = long(2.592e+15)  # Maximum nanoseconds, equal to the number of nanoseconds in a 30-day month

    if timeout_in_ns > max_timeout_in_ns:
        raise ValueError("Timeout exceeds 30-day month limit")

    log.debug("Waiting for up to %.2fs for %s", self.timeout, reason, extra={"sock": self})
    
    started = time.time()
    result = waiter(timeout_in_ns, TimeUnit.NANOSECONDS)
    
    log.debug("Completed in %.2fs", time.time() - started, extra={"sock": self})
    
    if not result:
        if self.timeout == 0:
            raise error(errno.ETIMEDOUT, "Connection timed out")
        else:
            raise timeout(errno.ETIMEDOUT, "timed out")
    
    return result

I still need to check that using long here doesn't break anything, in case it did another idea that I have is to use float instead of int to manage the timeout. Which could work better than using long but it would probably take more time to make compatible with everything.

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
0