-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PubSub : Fix Publisher.shutdown should return promptly #4956
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4956 +/- ##
============================================
+ Coverage 50.33% 50.36% +0.03%
+ Complexity 23676 23667 -9
============================================
Files 2238 2233 -5
Lines 226057 225866 -191
Branches 24961 24959 -2
============================================
- Hits 113775 113750 -25
+ Misses 103678 103518 -160
+ Partials 8604 8598 -6
Continue to review full report at Codecov.
|
for (AutoCloseable closeable : closeables) { | ||
ExecutorAsBackgroundResource executorAsBackgroundResource = | ||
(ExecutorAsBackgroundResource) closeable; | ||
isAwaited = executorAsBackgroundResource.awaitTermination(duration, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user is asking for something like: wait for 8 seconds total for termination.
publisherStub.awaitTermination(duration, unit);
could take 2.1 seconds. The next await termination should wait 8-2.1 seconds.
Please keep track of the start time, and the number of millis that have gone by since the method was invoked, and then wait the remainder of the users requested timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sduskis changes done
for (AutoCloseable closeable : closeables) { | ||
closeable.close(); | ||
ExecutorAsBackgroundResource executorAsBackgroundResource = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closable.close()
calls shutdown()
under the covers. There's no need to cast to a ExecutorAsBackgroundResource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sduskis changes done
long remainingDuration = TimeUnit.MILLISECONDS.convert(duration, unit); | ||
messagesWaiter.waitNoMessages(); | ||
remainingDuration = getRemainingDuration(remainingDuration, startDuration); | ||
startDuration = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't update startDuration
@@ -430,7 +429,32 @@ public void shutdown() throws Exception { | |||
* <p>Call this method to make sure all resources are freed properly. | |||
*/ | |||
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { | |||
return publisherStub.awaitTermination(duration, unit); | |||
long startDuration = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make startDuration
final. There's never a need to update it, since startDuration represents the start time when the method was called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sduskis startDuration needs to be update because it is used(counting) to find elapsed time which occur to execute waitNoMessages method only, so we have to minus this time from actual time pass to duration parameter of awaitTermination method and so on needs to update every time to find elapsed time so we can remove it from total remaining time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand what you mean. Let's have a static startTime
and totalDurationMs
variables that are final. We can use those plus current time to calculate remainingDurationMs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sduskis chnages done
@@ -430,7 +429,37 @@ public void shutdown() throws Exception { | |||
* <p>Call this method to make sure all resources are freed properly. | |||
*/ | |||
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { | |||
return publisherStub.awaitTermination(duration, unit); | |||
final long startDuration = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this variable startTimeMs
ExecutorAsBackgroundResource executorAsBackgroundResource = | ||
(ExecutorAsBackgroundResource) closeable; | ||
remainingDuration = getRemainingDuration(startDuration, totalDurationMs); | ||
System.out.println(remainingDuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this println.
return false; | ||
} | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the else.
} else { | ||
return false; | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use return isAwaited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sduskis changes done
bb5718c
to
4bc01c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you had a bad merge here. There are some changes that your PR reverted. Please update the PR to only change the thins you intended to change.
…n method" This reverts commit 4bc01c7
@abhinav-qlogic closing this PR due to lot of unintended merge/conflict. Please create new with just your change. |
Fixes #3687