-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fixing high CPU and memory leak in session pump #5493
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,9 +104,9 @@ public class CoreMessageReceiver extends ClientEntity implements IAmqpReceiver, | |||||||
| private CompletableFuture<Void> receiveLinkReopenFuture; | ||||||||
| private final Runnable timedOutUpdateStateRequestsDaemon; | ||||||||
| private final Runnable returnMesagesLoopDaemon; | ||||||||
| private final ScheduledFuture<?> updateStateRequestsTimeoutChecker; | ||||||||
| private final ScheduledFuture<?> returnMessagesLoopRunner; | ||||||||
| private final MessagingEntityType entityType; | ||||||||
| private ScheduledFuture<?> updateStateRequestsTimeoutChecker; | ||||||||
| private ScheduledFuture<?> returnMessagesLoopRunner; | ||||||||
|
|
||||||||
| // TODO: Change onReceiveComplete to handle empty deliveries. Change onError to retry updateState requests. | ||||||||
| private CoreMessageReceiver(final MessagingFactory factory, | ||||||||
|
|
@@ -145,6 +145,12 @@ private CoreMessageReceiver(final MessagingFactory factory, | |||||||
|
|
||||||||
| this.timedOutUpdateStateRequestsDaemon = () -> { | ||||||||
| try { | ||||||||
| if (CoreMessageReceiver.this.getIsClosed()) | ||||||||
| { | ||||||||
| CoreMessageReceiver.this.updateStateRequestsTimeoutChecker.cancel(true); | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| TRACE_LOGGER.trace("Starting '{}' core message receiver's internal loop to complete timed out update state requests.", CoreMessageReceiver.this.receivePath); | ||||||||
| for (Map.Entry<String, UpdateStateWorkItem> entry : CoreMessageReceiver.this.pendingUpdateStateRequests.entrySet()) { | ||||||||
| Duration remainingTime = entry.getValue().getTimeoutTracker().remaining(); | ||||||||
|
|
@@ -167,6 +173,12 @@ private CoreMessageReceiver(final MessagingFactory factory, | |||||||
| // CONTRACT: message should be delivered to the caller of MessageReceiver.receive() only from prefetched messages | ||||||||
| this.returnMesagesLoopDaemon = () -> { | ||||||||
| try { | ||||||||
| if (CoreMessageReceiver.this.getIsClosed()) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| { | ||||||||
| CoreMessageReceiver.this.returnMessagesLoopRunner.cancel(true); | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| TRACE_LOGGER.trace("Starting '{}' core message receiver's internal loop to return messages to waiting clients.", CoreMessageReceiver.this.receivePath); | ||||||||
| while (!CoreMessageReceiver.this.prefetchedMessages.isEmpty()) { | ||||||||
| ReceiveWorkItem currentReceive = CoreMessageReceiver.this.pendingReceives.poll(); | ||||||||
|
|
@@ -187,11 +199,6 @@ private CoreMessageReceiver(final MessagingFactory factory, | |||||||
| // Shouldn't throw any exception for the executor to run multiple times.. Should never come here | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| // As all update state requests have the same timeout, one timer is better than having one timer per request | ||||||||
| this.updateStateRequestsTimeoutChecker = Timer.schedule(timedOutUpdateStateRequestsDaemon, CoreMessageReceiver.UPDATE_STATE_REQUESTS_DAEMON_WAKE_UP_INTERVAL, TimerType.RepeatRun); | ||||||||
| // Scheduling it as a separate thread that wakes up at regular very short intervals.. Doesn't wait on incoming receive requests from callers or incoming deliveries from reactor | ||||||||
| this.returnMessagesLoopRunner = Timer.schedule(returnMesagesLoopDaemon, CoreMessageReceiver.RETURN_MESSAGES_DAEMON_WAKE_UP_INTERVAL, TimerType.RepeatRun); | ||||||||
| } | ||||||||
|
|
||||||||
| // Connection has to be associated with Reactor before Creating a receiver on it. | ||||||||
|
|
@@ -522,6 +529,11 @@ public void onOpenComplete(Exception exception) { | |||||||
| if (exception == null) { | ||||||||
| if (this.linkOpen != null && !this.linkOpen.getWork().isDone()) { | ||||||||
| AsyncUtil.completeFuture(this.linkOpen.getWork(), this); | ||||||||
|
|
||||||||
| // As all update state requests have the same timeout, one timer is better than having one timer per request | ||||||||
| this.updateStateRequestsTimeoutChecker = Timer.schedule(timedOutUpdateStateRequestsDaemon, CoreMessageReceiver.UPDATE_STATE_REQUESTS_DAEMON_WAKE_UP_INTERVAL, TimerType.RepeatRun); | ||||||||
| // Scheduling it as a separate thread that wakes up at regular very short intervals.. Doesn't wait on incoming receive requests from callers or incoming deliveries from reactor | ||||||||
| this.returnMessagesLoopRunner = Timer.schedule(returnMesagesLoopDaemon, CoreMessageReceiver.RETURN_MESSAGES_DAEMON_WAKE_UP_INTERVAL, TimerType.RepeatRun); | ||||||||
| } | ||||||||
|
|
||||||||
| if (this.receiveLinkReopenFuture != null && !this.receiveLinkReopenFuture.isDone()) { | ||||||||
|
|
@@ -746,14 +758,15 @@ private void scheduleLinkOpenTimeout(final TimeoutTracker timeout) { | |||||||
| Timer.schedule( | ||||||||
| () -> { | ||||||||
| if (!linkOpen.getWork().isDone()) { | ||||||||
| CoreMessageReceiver.this.closeInternals(false); | ||||||||
| CoreMessageReceiver.this.setClosed(); | ||||||||
|
|
||||||||
| Exception operationTimedout = new TimeoutException( | ||||||||
| String.format(Locale.US, "%s operation on ReceiveLink(%s) to path(%s) timed out at %s.", "Open", CoreMessageReceiver.this.receiveLink.getName(), CoreMessageReceiver.this.receivePath, ZonedDateTime.now()), | ||||||||
| CoreMessageReceiver.this.lastKnownLinkError); | ||||||||
| TRACE_LOGGER.warn(operationTimedout.getMessage()); | ||||||||
| ExceptionUtil.completeExceptionally(linkOpen.getWork(), operationTimedout, CoreMessageReceiver.this, true); | ||||||||
|
|
||||||||
| CoreMessageReceiver.this.setClosing(); | ||||||||
| CoreMessageReceiver.this.closeInternals(false); | ||||||||
| CoreMessageReceiver.this.setClosed(); | ||||||||
| } | ||||||||
| }, | ||||||||
| timeout.remaining(), | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.