equodev / equo-ide

Equo IDE
Eclipse Public License 2.0
37 stars 9 forks source link

Support for concurrent operations - `P2 operation already in progress` #146

Open blacelle opened 1 year ago

blacelle commented 1 year ago

This issue relates (in term of context) with https://github.com/diffplug/spotless/issues/1687

Through Spotless, I end needing to run concurrent P2 invocations in the same environment. It fails with:

Caused by: com.diffplug.spotless.ThrowingEx$WrappedAsRuntimeException: java.io.IOException: Failed to load eclipse jdt formatter: java.lang.IllegalStateException: P2 operation already in progress, close other clients or delete stale lockfile at /tmp/cleanthat/user_home/.m2/repository/dev/equo/p2-data/repository/dev/equo/p2-data/metadata/.lock
--
at com.diffplug.spotless.ThrowingEx.asRuntime(ThrowingEx.java:92)
at com.diffplug.spotless.LazyForwardingEquality.state(LazyForwardingEquality.java:58)
at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:88)
at com.diffplug.spotless.Formatter.compute(Formatter.java:246)
at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
at eu.solven.cleanthat.spotless.SpotlessSession.doStuff(SpotlessSession.java:109)
at eu.solven.cleanthat.language.spotless.SpotlessLintFixer.lambda$doFormat$0(SpotlessLintFixer.java:55)
... 18 common frames omitted
Caused by: java.io.IOException: Failed to load eclipse jdt formatter: java.lang.IllegalStateException: P2 operation already in progress, close other clients or delete stale lockfile at /tmp/cleanthat/user_home/.m2/repository/dev/equo/p2-data/repository/dev/equo/p2-data/metadata/.lock
at com.diffplug.spotless.extra.EquoBasedStepBuilder.get(EquoBasedStepBuilder.java:109)
at com.diffplug.spotless.FormatterStepImpl.calculateState(FormatterStepImpl.java:58)
at com.diffplug.spotless.LazyForwardingEquality.state(LazyForwardingEquality.java:56)
... 23 common frames omitted
Caused by: java.lang.IllegalStateException: P2 operation already in progress, close other clients or delete stale lockfile at /tmp/cleanthat/user_home/.m2/repository/dev/equo/p2-data/repository/dev/equo/p2-data/metadata/.lock
at dev.equo.solstice.p2.LockFile.lambda$new$0(LockFile.java:37)
at dev.equo.solstice.p2.FileMisc.retry(FileMisc.java:101)
at dev.equo.solstice.p2.LockFile.<init>(LockFile.java:31)
at dev.equo.solstice.p2.P2Client.<init>(P2Client.java:65)
at dev.equo.solstice.p2.P2Model.queryRaw(P2Model.java:94)
at dev.equo.solstice.p2.P2Model.query(P2Model.java:125)
at com.diffplug.spotless.extra.EquoBasedStepBuilder.get(EquoBasedStepBuilder.java:107)
... 25 common frames omitted

This is recurrent in my use-case as I run multiple Spotless|P2 processes on the same machine.

I have no equivalent issue with maven, which handles smoothly concurrent invocations on a common/shared ~/.m2/repository directory. Which makes me feel P2 could/should cover the same useCase.

I would be fine if concurrent operations were kept pending until the lock is freed, instead of hard-failing. This may be a relevant optional behavior.

nedtwigg commented 1 year ago

I agree it ought to handle concurrent invocations, or at the very least not fail while it waits in serial. In the short-term, the timeout goes from 5s to 50s if you set the system property lockFileGenerousTimeout to true.

https://github.com/equodev/equo-ide/blob/8557b4fb222744b6abb7102db0dc640fdbf817f7/solstice/src/main/java/dev/equo/solstice/p2/LockFile.java#L23-L30

blacelle commented 1 year ago

The 50s generous timeout seems sufficient for my case. Thanks