From 0a30be55ef433400965ff76581213b23f0e59a4e Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Tue, 18 Apr 2023 15:57:55 +0200 Subject: [PATCH] fix: Use EqualReadWriteLocker with file locker to prevent deadlocks --- config/util/resource-locker/file.json | 10 ++-------- src/util/locking/FileSystemResourceLocker.ts | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/config/util/resource-locker/file.json b/config/util/resource-locker/file.json index 9c067c155..a75ee80d7 100644 --- a/config/util/resource-locker/file.json +++ b/config/util/resource-locker/file.json @@ -6,18 +6,12 @@ "@id": "urn:solid-server:default:ResourceLocker", "@type": "WrappedExpiringReadWriteLocker", "locker": { - "@type": "GreedyReadWriteLocker", + "@type": "EqualReadWriteLocker", "locker": { "@id": "urn:solid-server:default:FileSystemResourceLocker", "@type": "FileSystemResourceLocker", "args_rootFilePath": { "@id": "urn:solid-server:default:variable:rootFilePath" } - }, - "storage": { - "@id": "urn:solid-server:default:LockStorage" - }, - "suffixes_count": "count", - "suffixes_read": "read", - "suffixes_write": "write" + } }, "expiration": 6000 }, diff --git a/src/util/locking/FileSystemResourceLocker.ts b/src/util/locking/FileSystemResourceLocker.ts index 57ed70a19..6ad8018cd 100644 --- a/src/util/locking/FileSystemResourceLocker.ts +++ b/src/util/locking/FileSystemResourceLocker.ts @@ -53,6 +53,9 @@ function isCodedError(err: unknown): err is { code: string } & Error { /** * A resource locker making use of the [proper-lockfile](https://www.npmjs.com/package/proper-lockfile) library. * Note that no locks are kept in memory, thus this is considered thread- and process-safe. + * While it stores the actual locks on disk, it also tracks them in memory for when they need to be released. + * This means only the worker thread that acquired a lock can release it again, + * making this implementation unusable in combination with a wrapping read/write lock implementation. * * This **proper-lockfile** library has its own retry mechanism for the operations, since a lock/unlock call will * either resolve successfully or reject immediately with the causing error. The retry function of the library