You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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 timeoutslog.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})
ifnotresult:
ifself.timeout==0:
raiseerror(errno.ETIMEDOUT, "Connection timed out")
else:
raisetimeout(errno.ETIMEDOUT, "timed out")
returnresult
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 timeoutsmax_timeout_in_ns=long(2.592e+15) # Maximum nanoseconds, equal to the number of nanoseconds in a 30-day monthiftimeout_in_ns>max_timeout_in_ns:
raiseValueError("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})
ifnotresult:
ifself.timeout==0:
raiseerror(errno.ETIMEDOUT, "Connection timed out")
else:
raisetimeout(errno.ETIMEDOUT, "timed out")
returnresult
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.
Activity
Andrysqui commentedon Oct 11, 2024
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:
Use
longinstead ofintso that the value for the timeout isn't reduced:So now the function would look like:
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:
I still need to check that using
longhere doesn't break anything, in case it did another idea that I have is to usefloatinstead ofintto manage the timeout. Which could work better than usinglongbut it would probably take more time to make compatible with everything.