Skip to content

filesize(fd::Int32) seems broken in Julia 1.12 #14

@csvance

Description

@csvance

In shm.jl we have the following section:

        # Get the size of the existing shared memory object.
        try
            nbytes = Int(filesize(fd))
        catch err
            _close(fd)
            rethrow(err)
        end

It seems that in Julia 1.12 that calling filesize on a file descriptor doesn't work:

ERROR: MethodError: no method matching joinpath(::Int32)
The function `joinpath` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  joinpath(::Base.Filesystem.DirEntry, Any...)
   @ Base file.jl:1034
  joinpath(::AbstractString...)
   @ Base path.jl:346
  joinpath(::Union{Tuple, AbstractVector})
   @ Base path.jl:324

Stacktrace:
  [1] stat(path::Int32)
    @ Base.Filesystem ./stat.jl:235
  [2] filesize(path::Int32)
    @ Base.Filesystem ./stat.jl:587
  [3] InterProcessCommunication.SharedMemory(name::String, flags::Int32, mode::UInt32, len::Int64, volatile::Bool)
    @ InterProcessCommunication /cache/cvance@medicalmetrics.local/julia/packages/InterProcessCommunication/cHeKQ/src/shm.jl:140
  [4] #SharedMemory#26
    @ /cache/cvance@medicalmetrics.local/julia/packages/InterProcessCommunication/cHeKQ/src/shm.jl:107 [inlined]
  [5] SharedMemory
    @ /cache/cvance@medicalmetrics.local/julia/packages/InterProcessCommunication/cHeKQ/src/shm.jl:103 [inlined]

I also can't find this specific signature in the documentation: https://docs.julialang.org/en/v1/base/file/#Base.filesize

Minimum workable example:

using Base.Filesystem
fd = UInt32(1234)
filesize(fd)

In Julia 1.11.7 the MWE produces this instead:

ERROR: IOError: stat(RawFD(1234)): bad file descriptor (EBADF)
Stacktrace:
 [1] uv_error
   @ ./libuv.jl:106 [inlined]
 [2] stat(fd::RawFD)
   @ Base.Filesystem ./stat.jl:176
 [3] stat
   @ ./stat.jl:192 [inlined]
 [4] filesize(path::UInt32)
   @ Base.Filesystem ./stat.jl:494
 [5] top-level scope
   @ REPL[3]:1

I patched this for my specific case by doing the following instead, but obviously this makes some major assumptions about the operating system:

            nbytes = Int(filesize("/dev/shm$(name)"))

Is this an issue with upstream in Base.Filesystem, or is this something we should try to fix here? I reported the difference in behavior to upstream just incase this was unintentional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions