Skip to content

HDDS-6658. BackgroundPipelineCreator does not always stop quickly#3357

Merged
szetszwo merged 1 commit into
apache:masterfrom
sodonnel:HDDS-6658
Apr 28, 2022
Merged

HDDS-6658. BackgroundPipelineCreator does not always stop quickly#3357
szetszwo merged 1 commit into
apache:masterfrom
sodonnel:HDDS-6658

Conversation

@sodonnel

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

On my laptop, TestSCMSafeModeManager.testSafeModePipelineExitRule() always takes just over 200 seconds. Checking a few PR runs, it does not seem to be slow on PRs, just locally.

Debugging the code, it seems to hang in the BackgroundPipelineCreator.stop() method, where it is waiting for the tread to join:

  public void stop() {
    if (!running.compareAndSet(true, false)) {
      LOG.warn("{} is not running, just ignore.", THREAD_NAME);
      return;
    }

    LOG.info("Stopping {}.", THREAD_NAME);

    // in case RatisPipelineUtilsThread is sleeping
    synchronized (monitor) {
      monitor.notifyAll();
    }

    try {
      thread.join();  //  ----> Hangs here
    } catch (InterruptedException e) {
      LOG.warn("Interrupted during join {}.", THREAD_NAME);
      Thread.currentThread().interrupt();
    }
  }

It is clearly hanging as the background thread did not exit, and I believe it is because notify() is being used to try to exit the thread, when it should really be interrupted. There is a chance that notify is called while the thread is not waiting, and if so, it will just fall back into the wait state and not exit until it wakes up again.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-6658

How was this patch tested?

Validated slow test is now fast locally.

@swagle
swagle requested a review from szetszwo April 27, 2022 15:50
@sodonnel

Copy link
Copy Markdown
Contributor Author

Unit test failure:

Failures: 
Error:    TestBackgroundPipelineScrubber.testRun:97 

This is #3359 / #3359

@szetszwo szetszwo left a comment

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.

@sodonnel , thanks for working on this. The change looks good. Just two minor comments inlined.

Comment on lines 151 to 152

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.

We should remove "synchronized" since interrupt() does not require it.

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.

I suggest to keep the private monitor field. It can avoid code outside this class calling wait/notify/notifyAll.

@sodonnel

Copy link
Copy Markdown
Contributor Author

@szetszwo Thanks for the review. I have rolled back the earlier changes and implemented again in a new commit. Please have another look when you get a chance.

@szetszwo szetszwo left a comment

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.

+1 the change looks good.

@szetszwo
szetszwo merged commit c251258 into apache:master Apr 28, 2022
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