gagaradio opened a new issue, #3173:
URL: https://github.com/apache/hertzbeat/issues/3173
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
If a task in `HashedWheelTimer` is canceled after being transferred to a
bucket and before being executed, `pendingTimeouts` may be repeatedly
decremented.
For example, the following code in `expireTimeouts(long)` of
`HashedWheelBucket` simulates this situation and ends up with a negative
`pendingTimeouts.`
```
while (timeout != null) {
HashedWheelTimeout next = timeout.next;
// Simulate that a task is canceled after being transferred to a bucket
and before being executed.
timeout.cancel();
if (timeout.remainingRounds <= 0) {
next = remove(timeout);
if (timeout.deadline <= deadline) {
timeout.expire();
} else {
// The timeout was placed into a wrong slot. This should never
happen.
throw new IllegalStateException(String.format(
"timeout.deadline (%d) > deadline (%d)",
timeout.deadline, deadline));
}
} else if (timeout.isCancelled()) {
next = remove(timeout);
} else {
timeout.remainingRounds--;
}
timeout = next;
}
```

### Expected Behavior
The `pendingTimeouts` in `HashedWheelTimer` can correctly reflect the number
of waiting tasks.
### Steps To Reproduce
_No response_
### Environment
```markdown
HertzBeat version(s): The latest master branch.
```
### Debug logs
_No response_
### Anything else?
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]