gauge-java icon indicating copy to clipboard operation
gauge-java copied to clipboard

"java.lang.IllegalStateException: zip file closed" in multithreading execution

Open stefan-spiess opened this issue 4 years ago • 2 comments

We have a Gauge project with step implemenations in an external JAR file located in the libs/ directory and execute the specs in parallel.

Expected behavior

The specs should run successfully in parallel with the following properties set:

enable_multithreading=true
package_to_scan=our.steps.directory

Actual behavior

The spec execution fails with the following exception:

Error ----------------------------------

[java]
Error in thread 19
zip file closed
java.lang.IllegalStateException: zip file closed
	at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:915)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:518)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:494)
	at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:31)
	at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:26)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
	at org.reflections.Reflections.scan(Reflections.java:243)
	at org.reflections.Reflections.scan(Reflections.java:202)
	at org.reflections.Reflections.<init>(Reflections.java:123)
	at com.thoughtworks.gauge.execution.parameters.parsers.base.ParameterParsingChain.createReflections(ParameterParsingChain.java:47)
	at com.thoughtworks.gauge.execution.parameters.parsers.base.ParameterParsingChain.<init>(ParameterParsingChain.java:33)
	at com.thoughtworks.gauge.connection.MessageProcessorFactory.initializeExecutionMessageProcessors(MessageProcessorFactory.java:112)
	at com.thoughtworks.gauge.connection.MessageProcessorFactory.getProcessor(MessageProcessorFactory.java:87)
	at com.thoughtworks.gauge.RunnerServiceHandler.lambda$initializeSpecDataStore$2(RunnerServiceHandler.java:76)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

[java]
Error in thread 20
zip file closed
java.lang.IllegalStateException: zip file closed
	at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:915)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:518)
	at java.base/java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:494)
	at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:31)
	at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:26)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
	at org.reflections.Reflections.scan(Reflections.java:243)
	at org.reflections.Reflections.scan(Reflections.java:202)
	at org.reflections.Reflections.<init>(Reflections.java:123)
	at com.thoughtworks.gauge.execution.parameters.parsers.base.ParameterParsingChain.createReflections(ParameterParsingChain.java:47)
	at com.thoughtworks.gauge.execution.parameters.parsers.base.ParameterParsingChain.<init>(ParameterParsingChain.java:33)
	at com.thoughtworks.gauge.connection.MessageProcessorFactory.initializeExecutionMessageProcessors(MessageProcessorFactory.java:112)
	at com.thoughtworks.gauge.connection.MessageProcessorFactory.getProcessor(MessageProcessorFactory.java:87)
	at com.thoughtworks.gauge.RunnerServiceHandler.lambda$initializeSpecDataStore$2(RunnerServiceHandler.java:76)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

[Gauge]
java runner quit unexpectedly. Check logs for more details.
ErrorMessage: transport is closing

Steps to reproduce

  1. Create gauge-java project
  2. Place a JAR file with your step implementations in the libs/ directory
  3. Set enable_multithreading=true and package_to_scan to your steps package
  4. Run gauge specs in parallel (-p)

Gauge version

Gauge version: 1.1.1
Plugins
-------
html-report (4.0.10)
java (0.7.9)
json-report (0.3.3)
screenshot (0.0.1)
xml-report (0.2.3)

Hints

According to https://github.com/ronmamo/reflections/issues/81 this might be an multithreading issue with the Reflections library version 0.9.11 used by the gauge-java plugin.

stefan-spiess avatar Aug 13 '20 13:08 stefan-spiess

@stefan-valtech I tried to replicate this but got no luck. The execution happened as expected. I have created a repo with a sample project which I used to replicate. https://github.com/BugDiver/gauge-java-489 Could you please check if you could replicate the issue on this, you can modify the project accordingly

BugDiver avatar Aug 17 '20 07:08 BugDiver

@BugDiver I tried to replicate this bug too and got the same error as above. To reproduce the bug i had to add more specs, so gauge runs it with more than 2 threads. (I checked out your repo, duplicated the specs and ran it also with gauge run specs -p) Nevertheless, sometimes it ran without any problems. If i run it with gauge run specs -p -n=2 the execution happens as expected.

According to https://github.com/ronmamo/reflections/issues/81 this, i also tried to compile and install the gauge-java plugin with the downgraded version of reflections as mentioned there. This worked fine for me.

Gauge version

Gauge version: 1.1.1
Commit Hash: 6e0d83f

Plugins
-------
html-report (4.0.12)
java (0.7.9)
json-report (0.3.3)
screenshot (0.0.1)
spectacle (0.1.4)
xml-report (0.2.3)

System

 Processor Name:	Quad-Core Intel Core i7
 Processor Speed:	2,5 GHz
 Number of Processors:	1
 Total Number of Cores:	4
 Hyper-Threading Technology:	Enabled

 System Version:	macOS 10.15.6 

ghost avatar Sep 17 '20 14:09 ghost