Open carlhoerberg opened 2 years ago
Maybe use pwritev2
with the RWF_SYNC
flag, but that's Linux only.. https://man7.org/linux/man-pages/man2/pwritev2.2.html
I'm hesitant to make that the default but it would be a nice option for Oj.to_stream
. What do you think?
Looking at this again. I think I misunderstood the desired changes. I don't think Oj should set the stream to non blocking but I do think Oj could handle EAGAIN errors along with some timeout value. I'm looking into that now.
Please try branch "non-blocking". Test added as well although I found the issue is exposed more readily with a large single write instead of many smaller ones and the test reflects that.
I believe the non-blocking branch fixes the issue. I plan to release tomorrow barring feedback from you indicating it is not fixed.
Okay to close?
is the patch included in oj 3.13.11? The example in the original issue still fails with it
Since Ruby 3.0 sockets are by default nonblocking, which causes issues for
Oj.to_stream
hereoutput:
set
s.nonblock = false
and it works as expected..Not sure if something should be done in
Oj
, but could be good for ppl to be aware.. It's not very ergonomic to catch the genericIOError
and then trying to figure out if it's aEAGAIN
error and manually doIO.select
.