[Date Prev][Date Next]
Using LMDB safely with fork() and exec()
- To: email@example.com
- Subject: Using LMDB safely with fork() and exec()
- From: Lorenz Bauer <firstname.lastname@example.org>
- Date: Mon, 22 Aug 2016 11:47:27 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=THfVyZK38qF4XfQvgoxoO++RSVA607OLLy0f2uMQUJ4=; b=ixHIRKALETVKfDkl2zVjN4bxrY7/n6r3nzhjw9GAQaYxkIqe5pVdwp4lCrfmjmhJ32 F/IMK9yAOnWjU8/e9TNtoltzCMfkUbyLfkfb2Z6fRx0n5xHA9sNX98j9Ibwj5+h9guEW ZtglA0fxWcMRodNhxI65slZvLkHd4fXupb0Q0=
The LMDB documentation says the following in its section on caveats:
> * Use an MDB_env* in the process which opened it, without fork()ing.
> * Do not have open an LMDB database twice in the same process at the same time. Not even from a plain open() call - close()ing it breaks flock() advisory locking.
This seems contrary to an earlier thread on this list (1), which
suggests that fork/execing a process using LMDB is OK so long as the
MDB_env is not used in the forked process. Looking at the flock man
pages on FreeBSD and Linux tells me that this indeed should be ok: an
flock is released only when all fds pointing to the open file table
entry are closed (ignoring explicit unlock). Exec with FD_CLOEXEC set
should therefore be OK.
Is my interpretation correct? I want to use this to implement graceful
restarts in a daemon which uses LMDB:
* mdb_env_open() in old process
* fork() -> exec() the daemon itself
* mdb_env_open() in new process
* mdb_env_close() in old process
If this works, I'd like to contribute the changes necessary to not
leak fds on exec, which are mentioned in the other thread.
* Are there contribution guidelines somewhere? How do I submit a patch?
* Seems like there is currently no call to SetHandleInformation with
HANDLE_FLAG_INHERIT=0 for Winows, should that be added?