Circular reference crash when reading fasta file

I have this piece of code :

function load_genome(genome_path, haschr=true)

    genome_index = string(genome_path,".fai")
    f = open(genome_path)
    reader = BioSequences.FASTA.Reader(f; index=genome_index)
    genome = Dict{String,BioSequences.BioSequence{BioSequences.DNAAlphabet{4}}}()
       
    @showprogress 1 "Loading genome..." for i in [map(string,1:22); "X"; "Y"]
        genome[i] = haschr ? BioSequences.FASTA.sequence(reader[string("chr",i)]) : BioSequences.FASTA.sequence(reader[string(i)])
    end
    close(f)
    genome
end

That read a genome in a FASTA format. Very occasionally (like once every 20 run) it crashes with this error message :

Loading genome... 12%|████▎                             |  ETA: 0:00:30Allocations: 170236237 (Pool: 170173950; Big: 62287); GC: 111
<?#0x11e0036b0::<circular reference @-1>>
0x136bbb000: Queued root: 0x15356a640 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbb018: Queued root: 0x1585fbea0 :: 0x1144a1920 (bits: 3)
        of type Method
0x136bbb030: Queued root: 0x1157a1070 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbb048: Queued root: 0x159f7db10 :: 0x11442ae20 (bits: 3)
        of type Core.MethodTable
0x136bbb060: Queued root: 0x1616c8430 :: 0x1144a1920 (bits: 3)
        of type Method

...

0x136bbc728: Queued root: 0x11e79baf0 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbc740: Queued root: 0x160806b90 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbc758: Queued root: 0x160806b30 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbc770: Queued root: 0x11e79bbb0 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbc788: Queued root: 0x11ea9e4d0 :: 0x11442b440 (bits: 3)
        of type Array{Any, 1}
0x136bbc7a0:  r-- Object (8bit) 0x11c2a2250 :: 0x1144a1da1 -- [2, 6)
        of type Core.MethodInstance
0x136bbc7c0:   - Object (8bit) 0x11c2a8160 :: 0x114427441 -- [3, 6)
        of type DataType

signal (6): Abort trap: 6
in expression starting at none:5
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 170236237 (Pool: 170173950; Big: 62287); GC: 111
[1]    7517 abort      julia

I never managed to reproduce it in a consistent manner, and I usually already have a lot of other packages loaded when that happens (I’m not sure it does if I run it alone), but it’s always during that loading part.

Any idea what the issue could be or how to investigate it ? What’s a circular reference anyway ?

Thanks.

The circular reference is the gc dump that’s most likely unrelated to the issue. This is most likely caused by incorrect usage of c interface

1 Like