Why sleep() throws EOFError?

I got this, but cannot reproduce it for now:

┌ Error: xxxx
│   exception =
│    EOFError: read end of file
│    Stacktrace:
│     [1] wait at ./asyncevent.jl:128 [inlined]
│     [2] sleep at ./asyncevent.jl:213 [inlined]
...

I see that wait(::Timer) (source) throws this when _trywait(::Timer) returns false. But the cause is not clear.

Is this a real error (maybe in another task) or should I just catch and ignore it?

Thanks in advance!

1 Like

Got an EOFError in a task from using sleep(::Float64). When and why does that happen?

function _trywait(t::Union{Timer, AsyncCondition})
    set = t.set
    if set
        # full barrier now for AsyncCondition
        t isa Timer || Core.Intrinsics.atomic_fence(:acquire_release)
    else
        t.isopen || return false
        t.handle == C_NULL && return false
        iolock_begin()
        set = t.set
        if !set
            preserve_handle(t)
            lock(t.cond)
            try
                set = t.set
                if !set && t.isopen && t.handle != C_NULL
                    iolock_end()
                    set = wait(t.cond)
                    unlock(t.cond)
                    iolock_begin()
                    lock(t.cond)
                end
            finally
                unlock(t.cond)
                unpreserve_handle(t)
            end
        end
        iolock_end()
    end
    @atomic :monotonic t.set = false
    return set
end

function wait(t::Union{Timer, AsyncCondition})
    _trywait(t) || throw(EOFError())
    nothing
end

That’s the code from julia/asyncevent.jl at v1.8.3 · JuliaLang/julia · GitHub

On Windows 8 with Julia 1.8.3