Giter Site home page Giter Site logo

Running clj-kondo with `--parallel` option sometimes fails with "Clj-kondo cache is locked by other thread or process" about clj-kondo HOT 7 OPEN

mrkam2 avatar mrkam2 commented on June 9, 2024
Running clj-kondo with `--parallel` option sometimes fails with "Clj-kondo cache is locked by other thread or process"

from clj-kondo.

Comments (7)

borkdude avatar borkdude commented on June 9, 2024

Do you have a test project where I can reproduce this? Without a repro there's not much I can do.

from clj-kondo.

mrkam2 avatar mrkam2 commented on June 9, 2024

from clj-kondo.

borkdude avatar borkdude commented on June 9, 2024

I guess you can run the modified version locally and see if you can find out more.

from clj-kondo.

mrkam2 avatar mrkam2 commented on June 9, 2024

So I added some logging to clj-kondo.impl.cache/with-cache and saw that pool-1-thread-N threads (N is 1..9 on my computer) compete for the cache lock. They make 1323 attempts to lock the file and 117 times these fail. Out of those failures 102 are the 0th retry (i. e. first try), 12 - at 1st retry, 2 - at 2nd retry, 1 - at 3rd retry:

retry# - count
0 - 102
1 - 12
2 - 2
3 - 1

I suspect that the number of parallel threads (as when run on a powerful CI host) creates increased contention which results in reaching the max retry attempts for some threads. My logging shows that the max number of retries is set to 6. So on my computer with 9 parallel threads it seems unlikely (although possible) to run into this issue. The number of processors is predefined in https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/core.clj#L364 so there isn't much I can currently do to change this. The number of retries is predefined in code in https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/analyzer/namespace.clj#L290 and in https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/cache.clj#L179.

I tried running locally with increased number of threads. With 26 threads, it failed to obtain lock 291 times and the retry counts were also higher:

retry# - count
0 - 194
1 - 64
2 - 17
3 - 8
4 - 4

It seems to me that to resolve the issue we should make either the number of retries higher and/or configurable or the number of parallel threads lower and/or configurable.

Thoughts?

from clj-kondo.

borkdude avatar borkdude commented on June 9, 2024

I don't know the exact answer of what tuning will be best, but maybe we could make threads configurable at least.

from clj-kondo.

mrkam2 avatar mrkam2 commented on June 9, 2024

I don't know the exact answer of what tuning will be best, but maybe we could make threads configurable at least.

I'd say we never want this to fail, so we probably should increase the number of retries. We could also potentially create a queue of cache updates so that they're guaranteed to execute in the order they happen and no thread is delayed too much.

from clj-kondo.

borkdude avatar borkdude commented on June 9, 2024

I like the queue idea

from clj-kondo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.