_get_osfhandle fails to map a file descriptor opened in Javascript to a handle.
Please see https://github.com/davedoesdev/node-windows-fd-test for a simple repro. It's also seen in https://github.com/baudehlo/node-fs-ext/issues/57 and https://github.com/nodejs/node-gyp/issues/416
I think this is due to MSVCR being statically linked into Node. _get_osfhandle can't find a descriptor opened in Javascript because the file descriptor to handle map in the Addon is separate to the one statically linked into the Node executable.
It would be nice to be able to use file descriptors passed into Addons on Windows. One idea is to expose _get_osfhandle (or a wrapper) from the Node executable for Addons to link against and call.
Related: https://github.com/nodejs/node/pull/6274. We need a way to re-export symbols that aren't marked __declspec(dllexport) but it's currently a right pain to do so.
The best way to go about it is probably to make the uv__get_osfhandle() function public.
https://github.com/libuv/libuv/blob/b12624c13693c4d29ca84b3556eadc9e9c0936a4/src/win/handle-inl.h#L165-L177
I'd rather make node properly re-export symbols. We need that anyway to make linking against openssl possible on Windows. I've been nibbling at it but it's slow going.
I tried to port mmap.js to windows (https://github.com/dimichgh/mmap.js/blob/master/src/winmmap.h#L58), but due to this issue, I am now blocked.
This is hard blocker for https://github.com/resin-io/etcher. I opened an issue in libuv. I'm happy to contribute a patch to make uv__get_osfhandle() public if they agree: https://github.com/libuv/libuv/issues/1291
It's a year to the day. Any progress on this?
@baudehlo I just sent a PR for this: https://github.com/libuv/libuv/pull/1323
I guess this was solved by https://github.com/libuv/libuv/pull/1323. Closing.
@bzoz yes indeed, it does work. I've updated my test app (https://github.com/davedoesdev/node-windows-fd-test, see first comment in this ticket) to use uv_get_osfhandle.
@jviotti thanks for fixing this.