Skip to content

Commit df7f915

Browse files
simaoafonso-pwtgitster
authored andcommitted
crendential-store: use timeout when locking file
When holding the lock for rewriting the credential file, use a timeout to avoid race conditions when the credentials file needs to be updated in parallel. An example would be doing `fetch --all` on a repository with several remotes that need credentials, using parallel fetching. The timeout can be configured using "credentialStore.lockTimeoutMS", defaulting to 1 second. Signed-off-by: Simão Afonso <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b291b0a commit df7f915

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Documentation/config/credential.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ credential.<url>.*::
2828

2929
credentialCache.ignoreSIGHUP::
3030
Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
31+
32+
credentialStore.lockTimeoutMS::
33+
The length of time, in milliseconds, for git-credential-store to retry
34+
when trying to lock the credentials file. Value 0 means not to retry at
35+
all; -1 means to try indefinitely. Default is 1000 (i.e., retry for
36+
1s).

builtin/credential-store.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "config.h"
23
#include "lockfile.h"
34
#include "credential.h"
45
#include "string-list.h"
@@ -58,8 +59,11 @@ static void print_line(struct strbuf *buf)
5859
static void rewrite_credential_file(const char *fn, struct credential *c,
5960
struct strbuf *extra)
6061
{
61-
if (hold_lock_file_for_update(&credential_lock, fn, 0) < 0)
62-
die_errno("unable to get credential storage lock");
62+
int timeout_ms = 1000;
63+
64+
git_config_get_int("credentialstore.locktimeoutms", &timeout_ms);
65+
if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
66+
die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
6367
if (extra)
6468
print_line(extra);
6569
parse_credential_file(fn, c, NULL, print_line);

0 commit comments

Comments
 (0)