Skip to content
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

Fix for Infinite loop in PersistentReplicator.startProducer() #275

Merged
merged 2 commits into from
Mar 4, 2017

Conversation

jai1
Copy link
Contributor

@jai1 jai1 commented Mar 3, 2017

Motivation

If replicator is stopped twice the state changes to "Stopping" and then when you start producer it goes into infinite loop. since there is a condition that checks if state is Stopping

Bug in #232

Modifications

Changed the logic and added comments for reasoning

Result

No inifinite loops in replication logic

@jai1
Copy link
Contributor Author

jai1 commented Mar 3, 2017

First commit solved the immediate problem - 072fe7e

Second commit restructures the code to solve both the immediate problem and the problem @rdhabalia had tried to fix - c1088ac4a2377a535f2503ffee2fd17331d3e1d9

@rdhabalia
Copy link
Contributor

can you please add the unit-test case where it tries to disconnect twice. first time it disconnects which stops producer, second time it should not flip the state and try to again restart the replicator which should restart it successfully.

Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

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

let's fix this one and we can put it in the patch.

|| STATE_UPDATER.compareAndSet(this, State.Started, State.Stopping))) {
if (producer == null) {
// If there's already a reconnection happening, signal to close it whenever it's ready
STATE_UPDATER.compareAndSet(this, State.Stopped, State.Stopped);
Copy link
Contributor

Choose a reason for hiding this comment

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

here essentially, we are setting the state Stopped if it's already Stopped. I don't think we need this here.

} else {
// If there's already a reconnection happening, signal to close it whenever it's ready
STATE_UPDATER.set(this, State.Stopping);
} else if (STATE_UPDATER.get(this) == State.Stopping) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need this else block because we actually don't do anything.
May be we can check in the beginning that if state is Stopping then return CompletableFuture.completedFuture(null)

@jai1 jai1 added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Mar 4, 2017
@jai1
Copy link
Contributor Author

jai1 commented Mar 4, 2017

@rdhabalia @saandrews - added test case

@jai1 jai1 self-assigned this Mar 4, 2017
@jai1 jai1 added type/bug The PR fixed a bug or issue reported a bug and removed type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Mar 4, 2017
@jai1 jai1 added this to the 1.17 milestone Mar 4, 2017
Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

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

👍

@rdhabalia rdhabalia merged commit 8544200 into apache:master Mar 4, 2017
rdhabalia pushed a commit that referenced this pull request Mar 4, 2017
* Fix for Infinite loop in PersistentReplicator.startProducer()

* Fix for Infinite loop in PersistentReplicator.startProducer()
@jai1 jai1 deleted the ReplicationFix branch March 6, 2017 17:42
hrsakai pushed a commit to hrsakai/pulsar that referenced this pull request Dec 10, 2020
Added microbenchmark to report compression and decompression speeds.
dlg99 pushed a commit to dlg99/pulsar that referenced this pull request May 28, 2024
dlg99 pushed a commit to dlg99/pulsar that referenced this pull request Sep 9, 2024
dlg99 pushed a commit to dlg99/pulsar that referenced this pull request Sep 16, 2024
dlg99 pushed a commit to dlg99/pulsar that referenced this pull request Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants