Bitbucket Cloud with SonarCloud integration
Scanner command used: ./gradlew build jacocoTestReport sonarqube
Gradle with sonarqube plugin: id “org.sonarqube” version “2.7.1”
Languages of the repository: Java and Javascript
Error observed: At the end of the build, we see the following in the output causing a delay for every pipeline using sonar:
:jacocoTestReport
:sonarqube
locking FileBasedConfig[/root/.config/jgit/config] failed after 5 retries
BUILD SUCCESSFUL
Steps to reproduce: Run any Bitbucket pipeline using the Gradle tasks listed above
Also, a build has failed with the following (passes normally, no changes have been committed):
locking FileBasedConfig[/root/.config/jgit/config] failed after 5 retries
:sonarqube FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sonarqube'.
> The 'report' parameter is missing
I changed the pipeline to run ./gradlew --refresh-dependencies --stacktrace build publish jacocoTestReport sonarqube, however there was no change to the build output:
The library we use to interact with git, JGit, uses file locks when saving jgit’s config to prevent concurrent write accesses.
Looking at their code, it looks like the look is implemented by atomically creating a file with a different extension for /root/.config/jgit/config. That is in the project’s base directory, right?
It’s happening at a step where no multithreading is used, so it’s unlikely that it’s a concurrent access within the process. It seems that the project is being analyzed concurrently by different processes.
I have the same error in, albeit for a different path of the config file:
WARN: locking FileBasedConfig[/home/scanner-cli/.config/jgit/config] failed after 5 retries
But since this is run during GitLab CI with the sonarsource/sonar-scanner-cli:4.2 Docker image, I am pretty sure this is not a race condition between different processes.
I found the root cause of the problem, and it’s a bug in JGit.
A deadlock happens when JGit’s configuration file and the git repository are located in different drives. However, I believe it has no impact to the scanner (other than the warning in the logs).
There is a workaround that will also speedup the execution of JGit and that we plan to implement in the next release of the Git SCM plugin: Log in with Atlassian account.
Since that’s likely not the cause of the error originally reported, have you seen again the error with “> The 'report' parameter is missing”, @jseletz?
Any debug logs of that?
.
.
.
JGits bug report: v5.6.1.202002131546-r
Description
If a git repository and JGit’s configuration file are located in different drives, JGit will fail to save the filesystem’s attributes when it runs for the first time.
The problem is that there is a deadlock involving the configuration file’s lock and the generation of both filesystem’s attributes.
Here is how the deadlock happens:
JGit tries to create a FileSnapshot for the repository’s index
Doesn’t have the FS attributes saved for that drive, so generates it
Proceeds to save it in the configuration file located in the other drive
Next it creates a lock file for the configuration file
Tries to create a FileSnapshot for the lock file.
Repeates steps 2-4 for the attributes of the other drive, and step 4 fails because the lock file already exists.
Impact
Note that it still manages to save the filesystem attributes for 1 of the drives, so next time it runs it will successfully save the attributes for the other drive. A warning is logged but it shouldn’t directly impact applications using the library.
Using 2 drives might sound like a corner case but turns out that CI pipelines with Atlassian and GitLab have this kind of setup in their worker nodes.
Reproducer
You’ll need 2 drives, let’s call them /d1 and /d2.