-
Notifications
You must be signed in to change notification settings - Fork 3.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
win,fs: don't modify global file translation mode #2324
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. Good catch too.
Perhaps you can remove uv_fs_init()
altogether since it's a stub now? It's called from core.c:
$ git grep -n uv_fs_init src/win
src/win/core.c:208: uv_fs_init();
src/win/fs.c:140:void uv_fs_init(void) {
src/win/internal.h:246:void uv_fs_init(void);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added a new commit to delete the now unused |
@jblazquez This PR seems to make a test fail consistently on Windows (failing on all hosts):
Can you take a look? I was kind of afraid libuv users implicitly depending on the value of Here is a Node.js integration CI for good measure: https://ci.nodejs.org/view/libuv/job/libuv-in-node/98/ |
Surprisingly, the Node integration CI seems to be OK. |
The MSVC runtime provides a global variable that can be used to set the default file translation mode so that file open calls don't need to explicitly specify that mode. libuv was changing that global mode to binary from its default of text. However, libuv doesn't actually need to do that anymore, and the application may not want the default changed under it. This change stops libuv from modifying that global mode.
@bnoordhuis you're right, that
I pushed a new change to make the test runner change the default file translation mode to binary, because that's what the tests are expecting. I agree that it is possible some existing users of libuv may be implicitly depending on the file mode being set to binary indirectly by the library. The
I understand if libuv decides that any chance of breaking an existing user is not acceptable and it would be better to keep this global state change in the library for the sake of those users, but it would be a shame being unable to ever walk back this code written so early in the project. Would a warning in the release notes or in the documentation about the file translation mode help appease these concerns? |
@libuv/collaborators It would be good if you could weigh in, and @vtjnash, perhaps you can check whether this breaks Julia? My own line of thought is that touching the global file mode in a library is a bug so I am (with some trepidation) in favor of landing this change. We would need to call it out clearly in the release notes, though. A note at the top of docs/src/fs.rst probably won't hurt either. |
It sure feels like a bug, I'm +1 on lading this. |
It won't break Julia since we don't use this LTS branch, and it's already gone from master. It does seem like a breaking change to do for other consumers though, especially since it breaks the tests. |
I'm OK with landing it. |
Hi, just wanted to point out that there is a similar issue (e.g modifying process wide settings) with |
+1 to landing. |
The MSVC runtime provides a global variable that can be used to set the default file translation mode so that file open calls don't need to explicitly specify that mode. libuv was changing that global mode to binary from its default of text. However, libuv doesn't actually need to do that anymore, and the application may not want the default changed under it. This change stops libuv from modifying that global mode. PR-URL: #2324 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in f9adfb2, thanks! Let's see how many bug reports we receive. :-) |
The MSVC runtime provides a global variable that can be used to set the default file translation mode so that file open calls don't need to explicitly specify that mode. libuv was changing that global mode to binary from its default of text. However, libuv doesn't actually need to do that anymore, and the application may not want the default changed under it. This change stops libuv from modifying that global mode. PR-URL: #2324 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
I rebased this commit out of the v1.x branch for the 1.30.1 patch release. Now that the release is out, I've landed this again as c905e0b. |
Fixes #1506. We don't use the uv_random interfaces so exclude those files. we don't support haiku so exclude that file. The binary mode patch for #1282 is no longer needed after libuv/libuv#2324
Back in 25175c when the filesystem API was initially implemented on Windows,
uv_fs_open
was internally implemented by calling the _open function. Shortly thereafter, in e1af07, the implementation was changed to use CreateFile instead. However, the code in uv_fs_init that was modifying the global _fmode variable to set the default file translation mode to binary was left in place, and has been there for 8 years.A library like libuv shouldn't be changing this global state, because the embedding application may need to use a different default file translation mode (this is how we found out libuv was doing this). Also, since the change to use CreateFile there's no longer a need for libuv to change this mode anyway, because it no longer uses either _open or _pipe, which are the functions that this global mode variable affects as per the docs.
This change stops libuv from changing this global state. All tests still pass after this change.