Skip to content
Prev Previous commit
Next Next commit
11622 : OutlierDetection should use Ticker, not TimeProvider
  • Loading branch information
vimanikag committed Jun 3, 2025
commit 3735a6c5d54b0b02b19812143bcadcad8d781992
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ private synchronized void fail(Status status) {
}

private synchronized void success() {
long currentTickerTimeNanos = ticker.read();
if (!done) {
done = true;
executor.execute(() -> callback.onSuccess(ticker.read() - startTimeNanos));
executor.execute(() -> callback.onSuccess(currentTickerTimeNanos - startTimeNanos));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion netty/src/main/java/io/grpc/netty/AbstractNettyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public void updateWindow() throws Http2Exception {
pingReturn++;
setPinging(false);

long elapsedTime = (ticker.read() - lastPingTime);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fine I believe, this doesn't need any change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the review comments

long currentTickerTimeNanos = ticker.read();
long elapsedTime = (currentTickerTimeNanos - lastPingTime);
if (elapsedTime == 0) {
elapsedTime = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
// On the first go we use the configured interval.
initialDelayNanos = config.intervalNanos;
} else {
Long currentTickerTimeNanos = ticker.read();
Long elepsedTimeNanos = currentTickerTimeNanos - detectionTimerStartNanos;
long currentTickerTimeNanos = ticker.read();
long elapsedTimeNanos = currentTickerTimeNanos - detectionTimerStartNanos;
// If a timer has started earlier we cancel it and use the difference between the start
// time and now as the interval.
initialDelayNanos = Math.max(0L,
config.intervalNanos - elepsedTimeNanos);
config.intervalNanos - elapsedTimeNanos);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep everything in-line here and above to make it less confusing. Storing in a variable doesn't change anything here, but sure you need to do Math.max(0L, ...) to not have any negative value there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure , I have addressed the review comments and added negative values check and moved everything to single line but's build has failed as it's reaching to 100 characters in line hence I am planning split it two lines

Screenshot 2025-06-06 8 03 45 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max is unnecessary. For it to overflow would require the process to be running for 292 years.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the review comments

}

// If a timer has been previously created we need to cancel it and reset all the call counters
Expand Down