Skip to content

race condition: upmap loses data when an exception is raised #73

@leahneukirchen

Description

@leahneukirchen

There seems to be some kind of race conditon in upmap such that an exception isn't caught, but processing is terminated and a partial result is returned.

I can reproduce this on claypoole 1.2.2, clojure 1.12.1, openjdk 21.0.7 on Linux x86_64, with a bit of experimentation:

(def thread-pool (com.climate.claypoole/threadpool 16))

(defn faulty [x]
  (let [n (rand-int 100)]
    (Thread/sleep 0 (rand-int 300000))
    (if (zero? n)
      (throw (ex-info "bad luck!" {}))
      x)))

(->> (range 1 100000)
     (mapv
      (fn [_]
        (try
          (into [] (com.climate.claypoole/upmap thread-pool faulty (range 0 50)))
          (catch Exception e
            nil))))
     (remove nil?)
     (remove #(= 50 (count %))))

At some point, this returns a 32-element vector. It probably helps if the JVM is busy in other ways to trigger this.

(We hit this issue in production with a way smaller workload. Bad luck!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions