leveldb icon indicating copy to clipboard operation
leveldb copied to clipboard

Use 'N' mode in fopen() to disable handle inheritance on Windows

Open k15tfu opened this issue 5 years ago • 10 comments

Fixes #623

k15tfu avatar Nov 27 '20 16:11 k15tfu

@cmumford Hi! Could you take a look?

k15tfu avatar Nov 28 '20 20:11 k15tfu

Hi @k15tfu

Thx for the PR (with tests). Even though the docs state that only one process can access a leveldb, I'm fine with adding a protection to help protect against accidental multi-process use. One problem is that this relies on a POSIX extension that is only available on Windows - please correct me if I'm wrong. I'm worried that this would wind up with application bugs that only show up on non-Windows platforms.

cmumford avatar Nov 30 '20 16:11 cmumford

@cmumford Hi! This is not for protection. Without this change, the log file handle leaks to child processes and therefore I cannot close DB and move/delete it until all handles are closed. So in my case it fails until the child process exits.

In this PR I change only Windows specific files and use platform-dependent N mode for fopen() (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-140). A similar change was already done for fopen() in env_posix.cc (https://github.com/google/leveldb/pull/624/files#diff-6e3e34528a780e660b519271c86d81c55519dcaf2fb7965fd0b232ae5cdcf0c5L677-R688), so now there should be no difference.

k15tfu avatar Nov 30 '20 17:11 k15tfu

@pwnall Friendly ping.

k15tfu avatar Dec 08 '20 09:12 k15tfu

@pwnall Friendly ping.

k15tfu avatar Dec 15 '20 11:12 k15tfu

@pwnall Friendly ping.

k15tfu avatar Dec 24 '20 12:12 k15tfu

@pwnall @cmumford Friendly ping.

k15tfu avatar Jan 11 '21 14:01 k15tfu

@pwnall @cmumford Friendly ping.

k15tfu avatar Mar 08 '21 21:03 k15tfu

Just an FYI, I know this is stale, but a similar change was merged a while ago: https://github.com/google/leveldb/pull/941

dktapps avatar Dec 20 '24 11:12 dktapps

Yup that's correct. Too sad that the corresponding test changes are still in this (stale) PR :(

ForNeVeR avatar Dec 20 '24 12:12 ForNeVeR