Skip to content

Commit

Permalink
Nospecialize close(c::Channel, excp::Exception) on excp. (#49508)
Browse files Browse the repository at this point in the history
* Nospecialize close(c::Channel, excp::Exception) on excp.

Fixes #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.
  • Loading branch information
NHDaly authored Apr 26, 2023
1 parent 3f7ae8b commit a152d11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,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

2 comments on commit a152d11

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.