summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorKoji Nakamaru <koji.nakamaru@gree.net>2024-05-15 21:21:06 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-15 23:02:44 +0200
commitfcf5b74e59c1c0d18a8e8e939475007b3b5f83ad (patch)
treeb23483534b6c26704fd63afd41e4e7f50e8ff697 /contrib
parentGit 2.45 (diff)
downloadgit-fcf5b74e59c1c0d18a8e8e939475007b3b5f83ad.tar.xz
git-fcf5b74e59c1c0d18a8e8e939475007b3b5f83ad.zip
osxkeychain: exclusive lock to serialize execution of operations
git passes a credential that has been used successfully to the helpers to record. If "git-credential-osxkeychain store" commands run in parallel (with fetch.parallel configuration and/or by running multiple git commands simultaneously), some of them may exit with the error "failed to store: -25299". This is because SecItemUpdate() in add_internet_password() may return errSecDuplicateItem (-25299) in this situation. Apple's documentation [1] also states as below: In macOS, some of the functions of this API block while waiting for input from the user (for example, when the user is asked to unlock a keychain or give permission to change trust settings). In general, it is safe to use this API in threads other than your main thread, but avoid calling the functions from multiple operations, work queues, or threads concurrently. Instead, serialize function calls or confine them to a single thread. The error has not been noticed before, because the former implementation ignored the error. Introduce an exclusive lock to serialize execution of operations. [1] https://developer.apple.com/documentation/security/certificate_key_and_trust_services/working_with_concurrency Signed-off-by: Koji Nakamaru <koji.nakamaru@gree.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/credential/osxkeychain/git-credential-osxkeychain.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/contrib/credential/osxkeychain/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
index 6a40917b1e..0884db48d0 100644
--- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c
+++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
@@ -414,6 +414,9 @@ int main(int argc, const char **argv)
if (!argv[1])
die("%s", usage);
+ if (open(argv[0], O_RDONLY | O_EXLOCK) == -1)
+ die("failed to lock %s", argv[0]);
+
read_credential();
if (!strcmp(argv[1], "get"))