Uploaded image for project: 'Clojure'
  1. CLJ-1528

clojure.test/inc-report-counter is not thread safe

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Completed
    • Affects versions: Release 1.7
    • Fix versions: Release 1.8
    • Labels:
    • Environment:

      OS X, Clojure 1.7, Macbook pro

    • Approval:
      Ok
    • Patch:
      Code

      Description

      clojure.test/inc-report-counter function combines dereferencing the report-counters ref and operating on the previous state of the ref, leading to race conditions during concurrent use.

      (dosync (commute *report-counters* assoc name
                       (inc (or (*report-counters* name) 0))))
      

      Approach: Rewrite update function to be entirely in terms of the old state:

      (dosync (commute *report-counters* update-in [name] (fnil inc 0)))
      

      Patch: fix-CLJ-1528.diff
      Screened by: Alex Miller

        Attachments

          Activity

            People

            • Assignee:
              aredington Alexander Redington
              Reporter:
              aredington Alexander Redington
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: