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

Prevent endless download of artifact sources/javadoc (#252) #303

Closed
wants to merge 1 commit into from

Conversation

HannesWell
Copy link
Contributor

The changes of this PR prevent endless download loops of sources/javadoc which can still occur under special circumstances as described in #252 (comment).

The approach is to maintain a set of handled download requests, that guards against adding an equivalent request that is/was already handled in the current run of the DownloadSources-job.

Alternatively the queue could be cleaned in the end of each run, but this could suppress legitimate follow up download requests, or can the latter never happen?

+ fix total-work computation in classpath-update
+ minor clean up
if(project == null || !project.isAccessible()) {
return;
}
queue.add(new DownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc));
DownloadRequest request = new DownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc);
if(requests.add(request)) { // guard against new requests that are/will be already downloaded in this run to prevent endless loops
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we start by something like !queue.contains(request) ? Wouldn't that already deliver a noticeable improvement without too much code complexity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately that would not help in the case described in #252 (comment), because the new request is added when DownloadSourcesJob.updateClasspath() is called in DownloadSourcesJob.run(). But at that point the queue is already empty, so it would be added again.

That's the reason why the requests are cleared after updateClasspath() is called.

Alternatively we could either

  • prevent BuildPathManager.updateClasspath() from creating new requests (but this would probably require more flags and also adds complexity).

or

  • simply clear the queue after updateClasspath() returned in DownloadSourcesJob.run().
    But, if any legitimate cases exists (do you know any?) where updateClasspath() creates follow-up downloads that downloads would be suppressed.

@mickaelistria
Copy link
Contributor

I admit I don't fully get the solution here; but since this has proven itself to be a fragile piece of code, it would be great if this bug could be covered by a test to prevent from future regression. Would that be doable?

@HannesWell
Copy link
Contributor Author

I admit I don't fully get the solution here; but since this has proven itself to be a fragile piece of code, it would be great if this bug could be covered by a test to prevent from future regression. Would that be doable?

Fully agree. I'll try to set up some test-cases.

@HannesWell
Copy link
Contributor Author

I admit I don't fully get the solution here; but since this has proven itself to be a fragile piece of code, it would be great if this bug could be covered by a test to prevent from future regression. Would that be doable?

I have created tests for this case and also other re-download cases and submitted them as a PR: tesla/m2e-core-tests#130

Without this PR the test BuildPathManagerTest.testDownloadSources_009_redownloadSnapshotWithOlderSources fails.
If you debug the test and put a break-point into DownloadSourcesJob where the request is added to the queue:
queue.add(request);

.. just before in BuildPathManagerTest.testDownloadSources_009_redownloadSnapshotWithOlderSources the download of sources/javadoc is scheduled the second time:

    // download sources a second time time
    getBuildPathManager().scheduleDownload(project, true, false);

You will noticed that the break-point is hit indefinitely if the job is not cancelled (what the test case does after 10 round IIRC). When you look into the stack-trace you will find what I have described here: #252 (comment)

@HannesWell
Copy link
Contributor Author

This PR should not be merged up until #318 and tesla/m2e-core-tests#130 are merged.

@mickaelistria
Copy link
Contributor

Great, thanks! Please rebase and merge when you're ready.

@mickaelistria
Copy link
Contributor

Rebased and merged as 7a56eef ; thanks!

@mickaelistria mickaelistria added this to the 1.18.2 milestone Sep 5, 2021
@HannesWell
Copy link
Contributor Author

Thanks for taking care of it.

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