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

#48 - Flush writer pipe; don't close it. #49

Merged
merged 2 commits into from
Jun 13, 2023
Merged

Conversation

NHDaly
Copy link
Contributor

@NHDaly NHDaly commented Dec 8, 2022

Fixes #48: Flush writer pipe; don't close it.

Since closing the pipe can cause race conditions with someone writing to the pipe, it's better to flush it, and then leave closing the pipe endpoint to GC.

@NHDaly
Copy link
Contributor Author

NHDaly commented Dec 8, 2022

CC: @dewilson, @vilterp

@NHDaly NHDaly changed the title #47759 - Flush writer pipe; don't close it. #48 - Flush writer pipe; don't close it. Jun 13, 2023
@quinnj quinnj closed this Jun 13, 2023
@quinnj quinnj reopened this Jun 13, 2023
Fixes #47759: Flush writer pipe; don't close it.

Since closing the pipe can cause race conditions with someone writing to the pipe, it's better to flush it, and then leave closing the pipe endpoint to GC.
This way we achieve all the goals:
- We close the writing task from our side, in a way that doesn't impact
  any other task that has captured the logger. The other task's output
  will just be silently dropped.
- We still allow the Pipe()s to be gracefully closed by GC, once they're
  no longer referenced.
# https://github.com/JuliaLang/julia/issues/40626)
@async nothing
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😕 okay SO: this does fix the tests, and this is now a working solution.

HOWEVER: It made me realize one other caveat with this approach.
Before, a task could throw an exception if it attempted to log from one thread while another thread is doing @capture_err.
NOW: it's possible for its log message to be SILENTLY DROPPED during that race condition, which is maybe just as bad?

So maybe the real answer is actually to fix JuliaLang/julia#47759 on the logger side, and leave this package alone? :/

It's sad because this fix seemed easier, but maybe less so now after these changes.

fetch(out_reader)
s = String(take!(io_buf))
# Now close the task to allow the Pipe() to be GC'd
close(io_buf)
Copy link
Member

Choose a reason for hiding this comment

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

I think at this point you need write something to the pipe and flush to make sure the task dies.

@quinnj quinnj merged commit 215c69a into JuliaIO:master Jun 13, 2023
NHDaly added a commit to NHDaly/Suppressor.jl that referenced this pull request Jun 14, 2023
quinnj pushed a commit that referenced this pull request Jun 14, 2023
@NHDaly NHDaly deleted the patch-1 branch June 14, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition when closeing the Pipe() used for redirect_*
3 participants