Skip to content

Commit d017d8c

Browse files
committed
Merge branch 'jt/config-lock-timeout' into jch
The code path to update the configuration file has been taught to use a short timeout to retry. Comments? * jt/config-lock-timeout: config: retry acquiring config.lock for 100ms
2 parents 6048dd4 + ab16b9a commit d017d8c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

config.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,14 @@ char *git_config_prepare_comment_string(const char *comment)
29342934
return prepared;
29352935
}
29362936

2937+
/*
2938+
* How long to retry acquiring config.lock when another process holds it.
2939+
* The lock is held only for the duration of rewriting a small file, so
2940+
* 100 ms covers any realistic contention while still failing fast if
2941+
* a stale lock has been left behind by a crashed process.
2942+
*/
2943+
#define CONFIG_LOCK_TIMEOUT_MS 100
2944+
29372945
static void validate_comment_string(const char *comment)
29382946
{
29392947
size_t leading_blanks;
@@ -3017,7 +3025,8 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
30173025
* The lock serves a purpose in addition to locking: the new
30183026
* contents of .git/config will be written into it.
30193027
*/
3020-
fd = hold_lock_file_for_update(&lock, config_filename, 0);
3028+
fd = hold_lock_file_for_update_timeout(&lock, config_filename, 0,
3029+
CONFIG_LOCK_TIMEOUT_MS);
30213030
if (fd < 0) {
30223031
error_errno(_("could not lock config file %s"), config_filename);
30233032
ret = CONFIG_NO_LOCK;
@@ -3362,7 +3371,8 @@ static int repo_config_copy_or_rename_section_in_file(
33623371
if (!config_filename)
33633372
config_filename = filename_buf = repo_git_path(r, "config");
33643373

3365-
out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
3374+
out_fd = hold_lock_file_for_update_timeout(&lock, config_filename, 0,
3375+
CONFIG_LOCK_TIMEOUT_MS);
33663376
if (out_fd < 0) {
33673377
ret = error(_("could not lock config file %s"), config_filename);
33683378
goto out;

0 commit comments

Comments
 (0)