Skip to content

Fix TypeError in exponential_delay function when handling connection timeouts #125

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jasil1414
Copy link

@jasil1414 jasil1414 commented Apr 2, 2025

Description

This PR fixes an issue where the NGINX Amplify Agent v1.8.3-1 crashes when experiencing connection timeouts to receiver.amplify.nginx.com on Ubuntu 24.04 Noble. The root cause is a TypeError in the exponential_delay function where a float value is being passed to random.randint() which requires integer arguments.

Environment

  • Ubuntu 24.04 Noble
  • NGINX Amplify Agent v1.8.3-1~noble
  • Python 3.12

Issue

When a connection timeout occurs, the agent attempts to use the exponential backoff mechanism, but crashes with:
TypeError: 'float' object cannot be interpreted as an integer

This causes the agent to completely stop instead of properly handling the timeout and retrying later.

Fix

The fix is a simple type conversion to ensure an integer is passed to the randint() function:

# Before
return randint(0, period_size - 1)

# After
return randint(0, int(period_size) - 1)


Fixes #124

…timeouts

Problem:
- Agent v1.8.3-1~noble crashes on Ubuntu 24.04 with TypeError when receiver.amplify.nginx.com times out
- Error occurs in backoff.py: "TypeError: 'float' object cannot be interpreted as an integer"
- The issue prevents proper exponential backoff during network connectivity problems
- Agent completely stops instead of retrying with the backoff delay

Solution:
- Add explicit integer type conversion to period_size before passing to randint()
- Convert: return randint(0, period_size - 1)
- To: return randint(0, int(period_size) - 1)

This fix allows the agent to properly handle connection timeouts without crashing.
The issue appears to be specific to Python 3.12 used in Ubuntu 24.04 Noble, as
the agent works correctly on Ubuntu 22.04 Jammy with Python 3.10.

Fixes nginxinc#124
@jasil1414 jasil1414 changed the title Fix TypeError in exponential_delay function when handling connection … Fix TypeError in exponential_delay function when handling connection timeouts Apr 2, 2025
@defanator defanator self-assigned this Apr 9, 2025
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

Successfully merging this pull request may close these issues.

2 participants