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

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

Merged
merged 3 commits into from
Apr 26, 2023
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
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
Comment on lines +630 to +631
Copy link
Member

Choose a reason for hiding this comment

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

I forgot I meant to say this should go into the stack_overflow.jl file, since the handling of this error is quite bad and sometimes ends up breaking the process (as I found out today trying to debug something completely unrelated). Do you mind making a PR to move it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, interesting. Yeah, i'm happy to move it! 👍 PR incoming

Copy link
Member Author

Choose a reason for hiding this comment

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

PR here: #49702

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