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 IgnoredReturnValue rule crash in parallel mode #5413

Merged
merged 1 commit into from
Oct 16, 2022
Merged

Conversation

schalkms
Copy link
Member

@schalkms schalkms commented Oct 14, 2022

IgnoredReturnValue crashes due to the usage of a non-thread-safe collection operation. The usage of Iterable<T>.plus() causes this problem. The crash in parallel mode is fixed by iterating over each collection by itself.

See here for more details in detekt v1.21:

(annotations + resultingDescriptor.containingDeclaration.annotations).none { it in returnValueAnnotations }

Closes #5403

IgnoredReturnValue crashes due to the usage of a non-thread-safe collection operation.
The usage of `Iterable<T>.plus()` causes this problem.
The crash in parallel mode is fixed by iterating over each collection by itself.

See here for more details in detekt v1.21:
https://github.com/detekt/detekt/blob/32f6e22d9524804ebbb51d31e53cd28a84864ed6/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt#L90

Closes #5403
@github-actions github-actions bot added the rules label Oct 14, 2022
@schalkms
Copy link
Member Author

I also checked with find usages whether detekt's code base contains related issues. No further issues have been found.

The questions is how we can prevent issues like this happening again in parallel mode.
I can also open a separate discussion if necessary.

@cortinico
Copy link
Member

The questions is how we can prevent issues like this happening again in parallel mode.

We do have ConTester in the codebase. @davidburstromspotify helped up set it up.
You should be able to stress test this scenario as well

@schalkms
Copy link
Member Author

@cortinico my question aimed for preventing such issues in general in the future. I’m not sure how a potential solution for a test could like.
For the scenario, which has been fixed with this PR, there’s no mutable collection/instructions anymore. If you look at the stack trace in the linked issue, you see that the code causing this crash is not executed anymore.

@davidburstromspotify
Copy link
Contributor

@cortinico ConTester unfortunately doesn't give you the required granular control in methods that are getting invoked, only in your own method implementations.

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Thanks for the insights. I think we're safe shipping this specific fix. As for preventing those kind of issues in the future, other than stress testing our rules with --parallel on CI, I don't have other ideas 🤔

@schalkms
Copy link
Member Author

hink we're safe shipping this specific fix. As for preventing those kind of issues in the future, other than stress testing our rules with --parallel on CI, I don't have other ideas

I like your idea. It is worthwhile to proceed. 👍

@schalkms
Copy link
Member Author

Still interesting that the line of code causing this crash was introduced 15 months ago and that only a few days the first issue appeared pointing to this line of code.

@schalkms schalkms merged commit 6274f21 into main Oct 16, 2022
@schalkms schalkms deleted the fix-#5403 branch October 16, 2022 11:05
@BraisGabin
Copy link
Member

I'm still puzzled by why that code is not parallel safe. Those are list provided by the PSI. Are those list changing? Is this related with the auto-correct feature?

@davidburstromspotify
Copy link
Contributor

I'm guessing wildly here, but if I read the stack trace correctly, the LazyJavaAnnotations is generated when calling plus, and if there are two references to LazyJavaAnnotations being addressed in parallel, it will crash. This could then be fixed by having a thread safe facade to LazyJavaAnnotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IgnoredReturnValue randomly crashes
4 participants