kubernetes: Int overflow in hpa causing incorrect replica count

What happened?

The setup: I am using keda with the prometheus scaler. The query I am using, returns the lag in the message queue i am using, and the threshold is set to 0.1.

What happened: The lag was increasing for a long time, and the replica count reached the max setting as expected. Everything was running fine for some time. When the lag value reached 214,748,364 hpa decided to reduce the replicas from the max limit to 1.

What I think is the problem: When the lag passes 214,748,364, the calculation here divides by the threshold 0.1 and it passes the max int32 value. causing hpa to scale to the minimum value, 1. It also seems like a lot of other places in this file cast a 64 bit float to a 32 bit int. Should there maybe be a check everywhere this is done?

What did you expect to happen?

I expected the replica count to stay at the max value. Or alternatively, get an error that we have reached the max value for an external metric value

How can we reproduce it (as minimally and precisely as possible)?

Use an external metric, and set it above 214,748,364 with a threshold of 0.1.

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
# paste output here

1.29

Cloud provider

aws eks

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Great to see #127050 was merged! Thanks for everyone involved. @omerap12 Are you planning to go forward with the other cases in this file like you mentioned here? To be honest, I’m not sure which of these unsafe casts are the cause for the original bug, so I don’t know if this issue is resolved or not.

Yeah, I re-opened it and assigned a reviewer. thanks for pinging 😃