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 license report task in multi-project setups #191

Merged
merged 3 commits into from
Apr 19, 2022

Conversation

fllink
Copy link
Contributor

@fllink fllink commented Apr 19, 2022

Currently running the license report task in multi-project setups is frequently causing the task to fail with "FWK005 parse may not be called while parsing." This is caused by the fact that LicenseReportTask.kt uses a static (companion) parser object. If parsing is already in progress for one project, a second report task on another project will fail if it tries to parse at the same time. This can be resolved by using an instance local parser variable.

Currently running the license report task in multi-project setups is frequently causing the task to fail with "FWK005 parse may not be called while parsing." This is caused by the fact that LicenseReportTask.kt uses a static (companion) parser object. If parsing is already in progress for one project, a second report task on another project will fail if it tries to parse at the same time. This can be resolved by using an instance local parser variable.
@jaredsburrows
Copy link
Owner

Anyway to write a test for this? Seems so odd? Can you post the actual error on this thread?

@jaredsburrows
Copy link
Owner

Can you at least a comment near this line of code to help explain the issue to prevent this in the future?

@fllink
Copy link
Contributor Author

fllink commented Apr 19, 2022

Hi Jared, first I wanted to take the chance to say big thanks to you for this really useful plugin! Thank you for taking the time to respond.

We use it on a multi-project gradle project, where it frequently exited with

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':relution:licenseReport'.
org.xml.sax.SAXException: FWK005 parse may not be called while parsing.

We tracked it down to e.g. here https://github.com/JetBrains/jdk8u_jaxp/blob/ef214d85066b758a01f9949298b255b8ffd8ab19/src/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java#L765 (depends on the XML parser configuration, but to get the idea) and from the source you can see that it happens if the parser is currently parsing - this will happen if one task analyses a POM file while another license report task is already parsing another POM file. We frequently encountered it when running ./gradlew sonarqube on our main project.

Writing a test is probably difficult, since the issue is behaving like a race condition and only happening sometimes. You could may be try to block the input stream in one parse call and then call another license task, but I guess since the logic was not really changed this would be kind of over engineered.

I will happily add a comment, I just wanted to follow the existing style and thus skipped it. Do you want it to be verbose, or shall I add a short comment, may be even linking to this pull request?

@jaredsburrows
Copy link
Owner

@fllink Thanks for the investigation. Can you just reference this PR in comment next to the code change, then we can merge this?

Ensure the issue is not re-introduced in the future, since it would be difficult to cover this with an actual test due to the race condition nature of the issue.
@fllink
Copy link
Contributor Author

fllink commented Apr 19, 2022

Sure, thank you for the quick response! Im currently trying to reproduce the issue again on our CI with stack trace, and will add it here as soon as it is available.

@jaredsburrows
Copy link
Owner

gradlew ktlintCheck has found a lint error. Try to format the project via gradlew ktlintFormat and then verify with gradlew ktlintCheck.

@fllink
Copy link
Contributor Author

fllink commented Apr 19, 2022

Stacktrace (I removed some lines from the gradle part):

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':relution:licenseReport'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$3(ExecuteActionsTaskExecuter.java:186)
	at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:268)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:184)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:173)
	...
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.gradle.internal.UncheckedException: org.xml.sax.SAXException: FWK005 parse may not be called while parsing.
	at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:67)
	at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:41)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:107)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
	at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
	...
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.xml.sax.SAXException: FWK005 parse may not be called while parsing.
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1258)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
	at com.jaredsburrows.license.LicenseReportTask.findLicenses(LicenseReportTask.kt:421)
	at com.jaredsburrows.license.LicenseReportTask.findLicenses(LicenseReportTask.kt:450)
	at com.jaredsburrows.license.LicenseReportTask.generatePOMInfo(LicenseReportTask.kt:188)
	at com.jaredsburrows.license.LicenseReportTask.licenseReport(LicenseReportTask.kt:63)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
	... 219 more

@jaredsburrows jaredsburrows merged commit 785cbe7 into jaredsburrows:master Apr 19, 2022
@jaredsburrows
Copy link
Owner

Thanks!

@fllink fllink deleted the patch-1 branch April 21, 2022 14:21
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.

None yet

2 participants