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

Make finalizer warning for shredded SecretBuffer async #33698

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/secretbuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function read(io::SecretBuffer, ::Type{UInt8})
end

function final_shred!(s::SecretBuffer)
!isshredded(s) && @warn("a SecretBuffer was `shred!`ed by the GC; use `shred!` manually after use to minimize exposure.")
!isshredded(s) && @async @warn("a SecretBuffer was `shred!`ed by the GC; use `shred!` manually after use to minimize exposure.")
shred!(s)
end

Expand Down
10 changes: 9 additions & 1 deletion test/secretbuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ using Test
@test !isshredded(secret_b)

# TODO: ideally we'd test that the finalizer warns from GC.gc(), but that is harder
@test_logs (:warn, r".*SecretBuffer was `shred!`ed by the GC.*") finalize(secret_b)
@test_logs (:warn, r".*SecretBuffer was `shred!`ed by the GC.*") begin
finalize(secret_b)
# Allow the async task which produces the SecretBuffer warning to run.
# This is a hack, but we don't have a way to get a handle to that
# task in order to `wait` on it.
for i=1:1000
yield()
end
end
@test isshredded(secret_b)
secret_b = nothing
GC.gc()
Expand Down