Skip to content

Ensure read/readavailable for BufferStream are threadsafe #57211

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

Merged
merged 3 commits into from
Feb 4, 2025

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Jan 31, 2025

It looks like these methods were just missed while overloading for BufferStream.

There's also readbytes! where the current implementation will fallback to the LibuvStream implementation that is currently not threadsafe. What's the best approach there since the implementation is quite a bit more involved? Just duplicate the code but for BufferStream? Should we take the BufferStream lock and invoke the LibuvStream method? Open to ideas there.

Also open to suggestions for having tests here? Not easy to simulate the data race of writing and calling readavailable.

The fix here will unblock JuliaWeb/HTTP.jl#1213 (I'll probably do some compat shim there until this is fully released).

Thanks to @oscardssmith for rubber ducking this issue with me.

Probably most helpfully reviewed by @vtjnash.

@quinnj
Copy link
Member Author

quinnj commented Feb 3, 2025

Ok, I just mostly copied the readbytes! implementation, tweaked for BufferStream. Previous CI run was all green, assuming this run is also all-green, I'll plan on merging in the next 24-hours. These changes don't seem too controversial and just match existing patterns. Please speak up if you feel otherwise.

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@quinnj
Copy link
Member Author

quinnj commented Feb 4, 2025

CI errors seem unrelated; merging

@quinnj quinnj merged commit ffc96bc into master Feb 4, 2025
5 of 7 checks passed
@quinnj quinnj deleted the jq-bufferstream-threadsafe-reads branch February 4, 2025 20:55
@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Feb 4, 2025
KristofferC pushed a commit that referenced this pull request Feb 6, 2025
It looks like these methods were just missed while overloading for
BufferStream.

There's also `readbytes!` where the current implementation will fallback
to the `LibuvStream` implementation that is currently not threadsafe.
What's the best approach there since the implementation is quite a bit
more involved? Just duplicate the code but for BufferStream? Should we
take the BufferStream lock and invoke the LibuvStream method? Open to
ideas there.

Also open to suggestions for having tests here? Not easy to simulate the
data race of writing and calling readavailable.

The fix here will unblock JuliaWeb/HTTP.jl#1213
(I'll probably do some compat shim there until this is fully released).

Thanks to @oscardssmith for rubber ducking this issue with me.

Probably most helpfully reviewed by @vtjnash.

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
(cherry picked from commit ffc96bc)
KristofferC pushed a commit that referenced this pull request Feb 6, 2025
It looks like these methods were just missed while overloading for
BufferStream.

There's also `readbytes!` where the current implementation will fallback
to the `LibuvStream` implementation that is currently not threadsafe.
What's the best approach there since the implementation is quite a bit
more involved? Just duplicate the code but for BufferStream? Should we
take the BufferStream lock and invoke the LibuvStream method? Open to
ideas there.

Also open to suggestions for having tests here? Not easy to simulate the
data race of writing and calling readavailable.

The fix here will unblock JuliaWeb/HTTP.jl#1213
(I'll probably do some compat shim there until this is fully released).

Thanks to @oscardssmith for rubber ducking this issue with me.

Probably most helpfully reviewed by @vtjnash.

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
(cherry picked from commit ffc96bc)
@KristofferC KristofferC mentioned this pull request Feb 6, 2025
32 tasks
KristofferC added a commit that referenced this pull request Feb 13, 2025
Backported PRs:
- [x] #57142 <!-- Add reference to time_ns in time -->
- [x] #57241 <!-- Handle `waitpid` race condition when `SIGCHLD` is set
to `SIG_IGN` -->
- [x] #57249 <!-- restore non-freebsd-unix fix for profiling -->
- [x] #57211 <!-- Ensure read/readavailable for BufferStream are
threadsafe -->
- [x] #57262 <!-- edit NEWS for v1.12 -->
- [x] #57226 <!-- cfunction: reimplement, as originally planned, for
reliable performance -->
- [x] #57253 <!-- bpart: Fully switch to partitioned semantics -->
- [x] #57273 <!-- fix "Right arrow autocompletes at line end"
implementation -->
- [x] #57280 <!-- dep: Update JuliaSyntax -->
- [x] #57229 <!-- staticdata: Close data race after backedge insertion
-->
- [x] #57298 <!-- Updating binding version to fix MMTk CI -->
- [x] #57248 <!-- improve concurrency safety for `Compiler.finish!` -->
- [x] #57312 <!-- Profile.print: de-focus sleeping frames as gray -->
- [x] #57289 <!-- Make `OncePerX` subtype `Function` -->
- [x] #57310 <!-- Make ptls allocations at least 128 byte aligned -->
- [x] #57311 <!-- Add a warning for auto-import of types -->
- [x] #57338 <!-- fix typo in Float32 random number generation -->
- [x] #57293 <!-- Fix getfield_tfunc when order or boundscheck is Vararg
-->
- [x] #57349 <!-- docs: fix-up world-age handling for META access -->
- [x] #57344 <!-- Add missing type asserts when taking the queue out of
the task struct -->
- [x] #57348 <!-- 🤖 [master] Bump the SparseArrays stdlib from 212981b
to 72c7cac -->
- [x] #55040 <!-- Allow macrocall as function sig -->
- [x] #57299 <!-- Add missing latestworld after parameterized type alias
-->
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Feb 13, 2025
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.

3 participants