-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Set IO to be sync for File
by default
#15236
base: master
Are you sure you want to change the base?
Set IO to be sync for File
by default
#15236
Conversation
737afc1
to
e764834
Compare
File
by defaultFile
by default
Somewhat meta: The wording around this is so bad. Why on earth is the base verb used That said I agree with the basic premise of matching the promises of the underlying OS by default, or at least to not be less safe than the OS. That way people will hopefully get less bad surprises even if things are too complicated in general: https://transactional.blog/how-to-learn/disk-io Also with things like |
I've been wondering this for a while, too. I went to open an issue about it but someone already had. #9023 😄 |
Also, the spec failures appear to be due to what @straight-shoota mentioned here. I think those specs should change, even if just to explicitly set |
Why should files behave differently to i.e. sockets here? If you call |
There is no difference from program terminating normally, no? |
I don't understand the question. They already behave differently, and this PR aligns them better. To illustrate what I mean, this program does not write the string to the file: file = File.open("output.txt", "w")
file.puts "this is some output"
sleep 100.milliseconds This program sends data over a socket, reads from the other end of the socket, and writes to require "socket"
spawn do
server = TCPServer.new(1234)
while incoming = server.accept?
spawn puts incoming.gets
end
end
socket = TCPSocket.new("localhost", 1234)
socket.puts "hi"
# Let the other fibers work
sleep 100.milliseconds The first one doesn't need the The second program outputs to STDOUT. The first does not write to the file. And that doesn't make any sense. |
If this is a concern, why would non-blocking, regular files still have buffered writes? |
Files are blocking by default, aren't they? crystal/src/io/file_descriptor.cr Lines 52 to 58 in b87d3e8
|
Well let's say I indeed passed |
I'm very verbose in my writing. If I didn't write something, chances are I wasn't suggesting it, either. What I did say in the very first sentence of this PR was that this is about the default behavior. The default settings are how people will use these most of the time, especially people who are less familiar with the language. At the moment, I don't have many opinions for when people override the default settings, tbh. |
Disabling write buffering when Why do you think the former is more appropriate than the latter? |
If this were true, wouldn't the All I'm looking for is for Crystal to do the safe thing by default. Nothing more than that. I don't understand why there is so much pushback. |
That example has nothing to do with my question. Maybe let me put it this way: class File
private def initialize(@path, fd : Int, blocking = false, encoding = nil, invalid = nil)
self.set_encoding(encoding, invalid: invalid) if encoding
super(fd, blocking)
end
end If I add |
I can't tell for sure, but I feel like your questions are leading toward pointing out that you would prefer to split out |
My apologies, I thought |
This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/using-wait-groups-with-http-server/7452/4 |
I'm sympathetic to disable output buffering for (ordinary) files by default. But I don't think this PR is the best way to do it. Before jumping to a new implementation, I believe this topic may need a bit more discussion. Changing such a default behaviour must be explored deeply to understand its effects. Especially since this affects the conceptual premise of streams in Crystal (this is already the case for sockets of course, but files makes it even more an issue). |
Since userspace buffers prevent Crystal from closing files automatically on program exit, maybe we should avoid using them for file I/O by default. Folks can enable userspace buffering explicitly if they need its benefits.
Fixes #13995