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

Update to 1309.ve21874387edf logs NullPointerException when old build is discarded #707

Open
PayBas opened this issue Sep 19, 2024 · 2 comments
Labels

Comments

@PayBas
Copy link
Contributor

PayBas commented Sep 19, 2024

Jenkins and plugins versions report

Environment
Jenkins: 2.462.2
OS: Linux - 6.10.10-200.fc40.x86_64
Java: 11.0.24 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)
---

What Operating System are you using (both controller, and any agents involved in the problem)?

Fedora 40, both for controller and agents

Reproduction steps

  1. Have a pipeline job that uses a lockable resource.
  2. Set a "Discard old builds" option with "Log Rotation" strategy and "Max # of builds to keep" = 3.
  3. Run the pipeline job 4 times.
  4. Observe the Jenkins controller logs.

Expected Results

No NPE

Actual Results

Sep 20, 2024 12:50:28 AM INFO org.jenkins.plugins.lockableresources.queue.LockRunListener onDeleted
my-pipeline-job resource1
Sep 20, 2024 12:50:28 AM WARNING jenkins.util.Listeners lambda$notify$0
null
java.lang.NullPointerException
	at PluginClassLoader for lockable-resources//org.jenkins.plugins.lockableresources.LockableResourcesManager.unlockBuild(LockableResourcesManager.java:655)
	at PluginClassLoader for lockable-resources//org.jenkins.plugins.lockableresources.queue.LockRunListener.onDeleted(LockRunListener.java:110)
	at hudson.model.listeners.RunListener.lambda$fireDeleted$4(RunListener.java:271)
	at jenkins.util.Listeners.lambda$notify$0(Listeners.java:59)
	at jenkins.util.Listeners.notify(Listeners.java:67)
	at hudson.model.listeners.RunListener.fireDeleted(RunListener.java:269)
	at hudson.model.Run.delete(Run.java:1646)
	at hudson.tasks.LogRotator.perform(LogRotator.java:167)
	at hudson.model.Job.logRotate(Job.java:486)
	at jenkins.model.JobGlobalBuildDiscarderStrategy.apply(JobGlobalBuildDiscarderStrategy.java:54)
	at jenkins.model.BackgroundGlobalBuildDiscarder.lambda$processJob$0(BackgroundGlobalBuildDiscarder.java:67)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at jenkins.model.BackgroundGlobalBuildDiscarder.processJob(BackgroundGlobalBuildDiscarder.java:61)
	at jenkins.model.BackgroundGlobalBuildDiscarder.execute(BackgroundGlobalBuildDiscarder.java:55)
	at hudson.model.AsyncPeriodicWork.lambda$doRun$0(AsyncPeriodicWork.java:102)
	at java.base/java.lang.Thread.run(Thread.java:829)

Anything else?

No response

Are you interested in contributing a fix?

No response

@PayBas PayBas added the bug label Sep 19, 2024
@jimklimov
Copy link
Contributor

jimklimov commented Sep 23, 2024

FWIW, this seems to be one of changes from PR #673, with new methods and lines at

public void unlockBuild(@Nullable Run<?, ?> build) {
if (build == null) {
return;
}
List<String> resourcesInUse =
LockedResourcesBuildAction.findAndInitAction(build).getCurrentUsedResourceNames();
if (resourcesInUse.size() == 0) {
return;
}
unlockNames(resourcesInUse, build);
}

An NPE at line 655 probably means resourcesInUse.size() failed because resourcesInUse == null.

One chance for that could be findAndInitAction() returning null (e.g. because build is null, which could make sense during deletion but we check just above that it is not - and a null at this point would throw NPE to call the next method in chain):

...or getCurrentUsedResourceNames() returning null because that what resourcesInUse would be?.. should not happen either, it is pre-initialized and never deleted AFAIK.

@Udo10744
Copy link

We have the same issue on Windows Server/Slaves, with a lightly different/detailed error message: Cannot invoke "java.util.List.size()" because "resourcesInUse" is null

2024-10-14 04:02:33.222+0000 [id=3374] INFO o.j.p.l.queue.LockRunListener#onDeleted: VCCP » A9 » Full #274 2024-10-14 04:02:33.222+0000 [id=3374] WARNING jenkins.util.Listeners#lambda$notify$0 java.lang.NullPointerException: Cannot invoke "java.util.List.size()" because "resourcesInUse" is null at PluginClassLoader for lockable-resources//org.jenkins.plugins.lockableresources.LockableResourcesManager.unlockBuild(LockableResourcesManager.java:655) at PluginClassLoader for lockable-resources//org.jenkins.plugins.lockableresources.queue.LockRunListener.onDeleted(LockRunListener.java:110) at hudson.model.listeners.RunListener.lambda$fireDeleted$4(RunListener.java:271) at jenkins.util.Listeners.lambda$notify$0(Listeners.java:59) at jenkins.util.Listeners.notify(Listeners.java:67) at hudson.model.listeners.RunListener.fireDeleted(RunListener.java:269) at hudson.model.Run.delete(Run.java:1646) at hudson.tasks.LogRotator.perform(LogRotator.java:182) at jenkins.model.SimpleGlobalBuildDiscarderStrategy.apply(SimpleGlobalBuildDiscarderStrategy.java:61) at jenkins.model.BackgroundGlobalBuildDiscarder.lambda$processJob$0(BackgroundGlobalBuildDiscarder.java:64) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at jenkins.model.BackgroundGlobalBuildDiscarder.processJob(BackgroundGlobalBuildDiscarder.java:60) at jenkins.model.BackgroundGlobalBuildDiscarder.execute(BackgroundGlobalBuildDiscarder.java:55) at hudson.model.AsyncPeriodicWork.lambda$doRun$0(AsyncPeriodicWork.java:102) at java.base/java.lang.Thread.run(Thread.java:1583)

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

No branches or pull requests

3 participants