Skip to content

Concurrent fit calls panic with RefCell already borrowed #120

@SamuelBadr

Description

@SamuelBadr

Summary

Concurrent calls to SparseIR.fit from multiple Julia threads panic with RefCell borrow errors.

Minimal Reproducer

using SparseIR
using Random
using Base.Threads: @threads, nthreads

Random.seed!(1)
basis = SparseIR.FiniteTempBasis{Fermionic}(0.7, 8.0, 1e-2)
sampling = SparseIR.MatsubaraSampling(basis)
n = length(SparseIR.sampling_points(sampling))
values = ComplexF64.(randn(n, 8), randn(n, 8))

@threads for _ in 1:nthreads()
    fit(sampling, values)
end

How To Run

Threaded (reproduces panic):

julia -t auto /path/to/reproducer.jl

Single-thread control (no panic):

julia -t 1 /path/to/reproducer.jl

Observed Output

thread '<unnamed>' panicked at sparse-ir/src/fitters/complex.rs:634:23:
RefCell already borrowed

Environment

  • Julia 1.12.5
  • SparseIR.jl 2.1.1
  • macOS arm64

I originally hit this in a larger solver stack, then reduced it to the snippet above.

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