Skip to content

Commit 3d8f81f

Browse files
committed
Merge branch 'sa/credential-store-timeout'
Multiple "credential-store" backends can race to lock the same file, causing everybody else but one to fail---reattempt locking with some timeout to reduce the rate of the failure. * sa/credential-store-timeout: crendential-store: use timeout when locking file
2 parents fa27e2d + df7f915 commit 3d8f81f

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)