Skip to content

INT-2751 Fix Reaper Race Condition - #627

Closed
garyrussell wants to merge 2 commits into
spring-projects:masterfrom
garyrussell:INT-2751
Closed

garyrussell wants to merge 2 commits into
spring-projects:masterfrom
garyrussell:INT-2751

Conversation

@garyrussell

Copy link
Copy Markdown
Contributor

When the reaper runs, and finds a group that is in the
process of being completed, the reaper blocks on the
lock, but when the lock is released, goes ahead and
reaps the group.

Now, after obtaining the lock, the reaper checks to
see if the modified date changed and, if so, aborts
the reap of the group this time around.

Required adding lastModified accounting for SimpleMessageGroup
(accounting already exists for other message groups).

Test case reproduced the problem, demonstrating duplicate
output messages.

After the fix, it shows the reap was aborted in the debug
log.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moving my comment from Commit to Diff

I think we can simplify it by modifying forceComplete() method which already holds the lock.
Basically modify its inner 'try' to look like this:

MessageGroup messageGroupNow = this.getMessageStore().getMessageGroup(group.getGroupId());
long lastModifiedNow = messageGroupNow.getLastModified();
if (group.getLastModified() == lastModifiedNow) {
    if (releaseStrategy.canRelease(group)) {
        this.completeGroup(correlationKey, group);
    }
    else {
        this.expireGroup(correlationKey, group);
    }
}

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.

Yep - good point - will change.

When the reaper runs, and finds a group that is in the
process of being completed, the reaper blocks on the
lock, but when the lock is released, goes ahead and
reaps the group.

Now, after obtaining the lock, the reaper checks to
see if the modified date changed and, if so, aborts
the reap of the group this time around.

Required adding lastModified accounting for SimpleMessageGroup
(accounting already exists for other message groups).

Test case reproduced the problem, demonstrating duplicate
output messages.

After the fix, it shows the reap was aborted in the debug
log.
PR Comments
@garyrussell

Copy link
Copy Markdown
Contributor Author

Rebased, polished, pushed - probably easier to look at full diff to see current state.

@olegz

olegz commented Sep 18, 2012

Copy link
Copy Markdown
Contributor

LGTM, merging

olegz added a commit to olegz/spring-integration that referenced this pull request Sep 18, 2012
* INT-2751:
  INT-2751 Fix Reaper Race Condition
@olegz olegz closed this Sep 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants