Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecretBuffer finalizer warning errors out with multiple tasks #33696

Closed
staticfloat opened this issue Oct 28, 2019 · 1 comment · Fixed by #33698
Closed

SecretBuffer finalizer warning errors out with multiple tasks #33696

staticfloat opened this issue Oct 28, 2019 · 1 comment · Fixed by #33698
Labels
domain:multithreading Base.Threads and related functionality kind:bug Indicates an unexpected problem or unintended behavior

Comments

@staticfloat
Copy link
Sponsor Member

staticfloat commented Oct 28, 2019

It looks like the helpful warning inside of the SecretBuffer finalizer causes multitasking to throw an error. To reproduce this, create a second task, then cause a SecretBuffer to be GC collected, triggering a warning being printed, followed by an error that task switching is not allowed within GC finalizers:

julia> @async begin
       sleep(10)
       println("Done!")
       end

       z = Base.SecretBuffer("foo")
       z = nothing
       GC.gc()
┌ Warning: a SecretBuffer was `shred!`ed by the GC; use `shred!` manually after use to minimize exposure.
└ @ Base secretbuffer.jl:169
┌ Error: Exception while generating log record in module Base at secretbuffer.jl:169
│   exception =
│    task switch not allowed from inside gc finalizer
│    Stacktrace:
│     [1] try_yieldto(::typeof(Base.ensure_rescheduled), ::Base.RefValue{Task}) at ./task.jl:602
│     [2] wait() at ./task.jl:668
│     [3] uv_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:935
│     [4] unsafe_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:1007
│     [5] unsafe_write at ./io.jl:593 [inlined]
│     [6] macro expansion at ./gcutils.jl:91 [inlined]
│     [7] write(::Base.TTY, ::Array{UInt8,1}) at ./io.jl:616
│     [8] #handle_message#2(::Nothing, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(Base.CoreLogging.handle_message), ::Logging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::String, ::Module, ::String, ::Symbol, ::String, ::Int64) at /Users/sabae/tmp/julia-build/julia-release-1.3/usr/share/julia/stdlib/v1.3/Logging/src/ConsoleLogger.jl:161
│     [9] handle_message at /Users/sabae/tmp/julia-build/julia-release-1.3/usr/share/julia/stdlib/v1.3/Logging/src/ConsoleLogger.jl:100 [inlined]
│     [10] macro expansion at ./logging.jl:320 [inlined]
│     [11] final_shred!(::Base.SecretBuffer) at ./secretbuffer.jl:169
│     [12] gc at ./gcutils.jl:60 [inlined] (repeats 2 t
imes)
│     [13] top-level scope at REPL[1]:8
│     [14] eval(::Module, ::Any) at ./boot.jl:330
│     [15] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/sabae/tmp/julia-build/julia-release-1.3/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:86
│     [16] macro expansion at /Users/sabae/tmp/julia-build/julia-release-1.3/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:118 [inlined]
│     [17] (::REPL.var"#26#27"{REPL.REPLBackend})() at ./task.jl:333
└ @ Base secretbuffer.jl:169
Done!

Perhaps the most infuriating thing is that it appears that everything worked properly, despite the fatal error.

@staticfloat staticfloat added kind:bug Indicates an unexpected problem or unintended behavior domain:multithreading Base.Threads and related functionality labels Oct 28, 2019
@c42f
Copy link
Member

c42f commented Oct 28, 2019

Oh ick. Somewhat related to #26687 and logging from other special contexts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:multithreading Base.Threads and related functionality kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants