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

Race condition & memory leak in TypedFilter #9925

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

jglick
Copy link
Member

@jglick jglick commented Oct 29, 2024

After starting a controller I got an “angry Jenkins” and in the log I saw

java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "java.util.Map.get(Object)" is null

coming from the line for staplerCache.get(clazz). This is not all that surprising, since it was a (non-Concurrent) HashMap, and I suppose this cache could be used from multiple page loading threads, so it would be expected to happen occasionally.

Also HashMap rather than WeakHashMap meant that the keys were held strongly. Probably not an issue for Jenkins, assuming this refers only to plugin classes, since plugins cannot be unloaded, but still a bad practice.

CacheValue handles both issues and is simpler to boot.

Testing done

Existing test passes.

Proposed changelog entries

  • Fix a rare race condition rendering pages soon after startup.

Proposed upgrade guidelines

N/A

Submitter checklist

Desired reviewers

Before the changes are marked as ready-for-merge:

Maintainer checklist

private static final ClassValue<Boolean> isStaplerRelevant = new ClassValue<>() {
@Override
protected Boolean computeValue(Class<?> clazz) {
return isSpecificClassStaplerRelevant(clazz) || isSuperTypesStaplerRelevant(clazz);
Copy link
Member Author

Choose a reason for hiding this comment

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

(hide WS)

@MarkEWaite
Copy link
Contributor

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.

/label ready-for-merge

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Oct 31, 2024
@MarkEWaite MarkEWaite merged commit e0a54f4 into jenkinsci:master Nov 2, 2024
15 checks passed
@jglick jglick deleted the TypedFilter branch November 4, 2024 18:13
@MarkEWaite MarkEWaite added the bug For changelog: Minor bug. Will be listed after features label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants