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

Backport PR 49508 #8

Closed
wants to merge 1 commit into from
Closed
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
Nospecialize close(c::Channel, excp::Exception) on excp. (JuliaLang#4…
…9508)

* Nospecialize close(c::Channel, excp::Exception) on excp.

Fixes JuliaLang#49507.

Avoids dynamic dispatch when closing a Channel with an Exception, and
should avoid a call into the runtime for julia compilation when
attempting to report an exception.

* Add test for this case.
NHDaly committed May 15, 2023
commit 40579c3c896522b41e83988d54d102dbec48329a
3 changes: 2 additions & 1 deletion base/channels.jl
Original file line number Diff line number Diff line change
@@ -183,7 +183,8 @@ Close a channel. An exception (optionally given by `excp`), is thrown by:
* [`put!`](@ref) on a closed channel.
* [`take!`](@ref) and [`fetch`](@ref) on an empty, closed channel.
"""
function close(c::Channel, excp::Exception=closed_exception())
close(c::Channel) = close(c, closed_exception()) # nospecialize on default arg seems to confuse makedocs
function close(c::Channel, @nospecialize(excp::Exception))
lock(c)
try
c.excp = excp
17 changes: 17 additions & 0 deletions test/channels.jl
Original file line number Diff line number Diff line change
@@ -619,3 +619,20 @@ end
@test n_avail(c) == 0
end
end

# Issue #49507: stackoverflow in type inference caused by close(::Channel, ::Exception)
@testset "close(::Channel, ::StackOverflowError)" begin
ch = let result = Channel()
foo() = try
foo()
catch e;
close(result, e)
end

foo() # This shouldn't fail with an internal stackoverflow error in inference.

result
end

@test (try take!(ch) catch e; e; end) isa StackOverflowError
end