julia icon indicating copy to clipboard operation
julia copied to clipboard

attach finalizer in `mmap` to the correct object

Open KristofferC opened this issue 1 year ago • 6 comments

Fixes https://github.com/JuliaLang/julia/issues/54128

KristofferC avatar Apr 23 '24 08:04 KristofferC

@vtjnash, this seems to make Mmap tests fail on Windows:

Mmap                                             (2) |         failed at 2024-04-23T11:08:39.378
Error During Test at C:\buildkite-agent\builds\win2k22-amdci6-5\julialang\julia-master\julia-39a8092b06\share\julia\test\testdefs.jl:24
  Got exception outside of a @test
  LoadError: SystemError: opening file "C:\\Users\\julia\\AppData\\Local\\Temp\\jl_MNqlAn4hyl": Invalid argument
  Stacktrace:
    [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
      @ Base .\error.jl:185
    [2] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Bool, append::Nothing)
      @ Base .\iostream.jl:298
    [3] open
      @ .\iostream.jl:277 [inlined]
    [4] open(fname::String, mode::String; lock::Bool)
      @ Base .\iostream.jl:361
    [5] open(fname::String, mode::String)
      @ Base .\iostream.jl:360
    [6] open(::Base.var"#470#471"{String, Tuple{}}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
      @ Base .\io.jl:408
    [7] open
      @ .\io.jl:407 [inlined]
    [8] write(::String, ::String)
      @ Base .\io.jl:489
    [9] top-level scope
      @ C:\buildkite-agent\builds\win2k22-amdci6-5\julialang\julia-master\julia-39a8092b06\share\julia\stdlib\v1.12\Mmap\test\runtests.jl:106
   [10] include

KristofferC avatar Apr 25 '24 12:04 KristofferC

@vtjnash, do you have an idea about the Windows CI mmap failures here?

KristofferC avatar May 06 '24 09:05 KristofferC

No idea. Seems to imply it isn't getting finalized (or finalized soon enough for it to be happy) but I didn't look at what that test expects of it to see if it was reasonable looking

vtjnash avatar May 07 '24 03:05 vtjnash

I tested this locally and the Mmap tests pass if I move the GC.gc() on line 103 out of the if block to right before the write. https://github.com/JuliaLang/julia/blob/39a8092b06d1f29ca431171e0ab526e6eb0c3478/stdlib/Mmap/test/runtests.jl#L103-L106

I also needed to move the GC.gc() on line 339 out of the do block to right before the rm. https://github.com/JuliaLang/julia/blob/39a8092b06d1f29ca431171e0ab526e6eb0c3478/stdlib/Mmap/test/runtests.jl#L339-L341

I have no idea why GC.gc() isn't calling all the finalizers when it's in an if block, but here is a simpler test I made for this:

if true
    foo = Ref(true)
    bar = Ref(foo)
    finalizer(x->x[][]=false, bar)
    bar=nothing
    GC.gc()
end
@info foo[]

This results in true, but moving the GC.gc() out of the if block:

if true
    foo = Ref(true)
    bar = Ref(foo)
    finalizer(x->x[][]=false, bar)
    bar=nothing
end
GC.gc()
@info foo[]

results in false

nhz2 avatar May 21 '24 02:05 nhz2

Still seem to error on CI.

KristofferC avatar May 22 '24 08:05 KristofferC

Adding a GC.gc() on line 105 should fix it.

nhz2 avatar May 22 '24 12:05 nhz2

That seems to have done it. Thanks for the help @nhz2

KristofferC avatar May 27 '24 12:05 KristofferC