Skip to content

fix(db-functions): fix locking issue that overwrote the same fd

Levente Polyak requested to merge fix-locking-fd-table into master

Calling acquire_fd in a subshell doesn't populate the global lockfd associate array properly. This resulted in the reuse of the same fd multiple times, effectively only holding a single latest lock and releasing any previous.

Fix the issue by avoiding a global variable that causes issues in subshell calls by using the file descriptor table directly. Instead of storing file descriptors, the lookup call iterates through all fds and checks their handle. In case a file is not yet opened, allocate the next free fd between 4 and 1023.

Operating directly on the file descriptor table has the nice side effect that we avoid reusing descriptors by accident in case they have been opened for none locking purpose within the statically defined range.

Reported-by: Felix Yan

Co-authored-by: Felix Yan

Signed-off-by: Levente Polyak

Edited by Levente Polyak

Merge request reports