git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] refs: drop "clear packed-refs while locked" assertion
@ 2017-12-08 11:22 Jeff King
  2018-01-01 15:26 ` Michael Haggerty
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff King @ 2017-12-08 11:22 UTC (permalink / raw)
  To: git; +Cc: Michael Haggerty

This patch fixes a regression in v2.14.0. It's actually fixed already in
v2.15.0 because all of the packed-ref code there was rewritten. So
there's no point in applying this on "master" or even "maint". But I
figured it was worth sharing here in case somebody else runs across it,
and in case we ever do a v2.14.4 release.

-- >8 --
In clear_packed_ref_cache(), we assert that we're not
currently holding the packed-refs lock. But in each of the
three code paths that can hit this, the assertion is either
a noop or actively does the wrong thing:

 1. in rollback_packed_refs(), we will have just released
    the lock before calling the function, and so the
    assertion can never trigger.

 2. get_packed_ref_cache() can reach this assertion via
    validate_packed_ref_cache(). But it calls the validate
    function only when it knows that we're not holding the
    lock, so again, the assertion can never trigger.

 3. lock_packed_refs() also calls validate_packed_ref_cache().
    In this case we're _always_ holding the lock, which
    means any time the validate function has to clear the
    cache, we'll trigger this assertion and die.

    This doesn't happen often in practice because the
    validate function clears the cache only if we find that
    somebody else has racily rewritten the packed-refs file
    between the time we read it and the time we took the lock.

    So most of the time we don't reach the assertion at all
    (nobody has racily written the file so there's no need
    to clear the cache). And when we do, it is not actually
    indicative of a bug; clearing the cache while holding
    the lock is the right thing to do here.

This final case is relatively new, being triggerd by the
extra validation added in fed6ebebf1 (lock_packed_refs():
fix cache validity check, 2017-06-12).

Signed-off-by: Jeff King <peff@peff.net>
---
 refs/files-backend.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index f21a954ce7..dd41e1d382 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -99,8 +99,6 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
 	if (refs->packed) {
 		struct packed_ref_cache *packed_refs = refs->packed;
 
-		if (is_lock_file_locked(&refs->packed_refs_lock))
-			die("BUG: packed-ref cache cleared while locked");
 		refs->packed = NULL;
 		release_packed_ref_cache(packed_refs);
 	}
-- 
2.15.1.659.g8bd2eae3ea

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] refs: drop "clear packed-refs while locked" assertion
  2017-12-08 11:22 [PATCH] refs: drop "clear packed-refs while locked" assertion Jeff King
@ 2018-01-01 15:26 ` Michael Haggerty
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Haggerty @ 2018-01-01 15:26 UTC (permalink / raw)
  To: Jeff King; +Cc: Git Mailing List

On Fri, Dec 8, 2017 at 12:22 PM, Jeff King <peff@peff.net> wrote:
> This patch fixes a regression in v2.14.0. It's actually fixed already in
> v2.15.0 because all of the packed-ref code there was rewritten. So
> there's no point in applying this on "master" or even "maint". But I
> figured it was worth sharing here in case somebody else runs across it,
> and in case we ever do a v2.14.4 release.

I forgot to respond to this. +1

Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>

Michael

> -- >8 --
> In clear_packed_ref_cache(), we assert that we're not
> currently holding the packed-refs lock. But in each of the
> three code paths that can hit this, the assertion is either
> a noop or actively does the wrong thing:
>
>  1. in rollback_packed_refs(), we will have just released
>     the lock before calling the function, and so the
>     assertion can never trigger.
>
>  2. get_packed_ref_cache() can reach this assertion via
>     validate_packed_ref_cache(). But it calls the validate
>     function only when it knows that we're not holding the
>     lock, so again, the assertion can never trigger.
>
>  3. lock_packed_refs() also calls validate_packed_ref_cache().
>     In this case we're _always_ holding the lock, which
>     means any time the validate function has to clear the
>     cache, we'll trigger this assertion and die.
>
>     This doesn't happen often in practice because the
>     validate function clears the cache only if we find that
>     somebody else has racily rewritten the packed-refs file
>     between the time we read it and the time we took the lock.
>
>     So most of the time we don't reach the assertion at all
>     (nobody has racily written the file so there's no need
>     to clear the cache). And when we do, it is not actually
>     indicative of a bug; clearing the cache while holding
>     the lock is the right thing to do here.
>
> This final case is relatively new, being triggerd by the
> extra validation added in fed6ebebf1 (lock_packed_refs():
> fix cache validity check, 2017-06-12).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  refs/files-backend.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index f21a954ce7..dd41e1d382 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -99,8 +99,6 @@ static void clear_packed_ref_cache(struct files_ref_store *refs)
>         if (refs->packed) {
>                 struct packed_ref_cache *packed_refs = refs->packed;
>
> -               if (is_lock_file_locked(&refs->packed_refs_lock))
> -                       die("BUG: packed-ref cache cleared while locked");
>                 refs->packed = NULL;
>                 release_packed_ref_cache(packed_refs);
>         }
> --
> 2.15.1.659.g8bd2eae3ea

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-01 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08 11:22 [PATCH] refs: drop "clear packed-refs while locked" assertion Jeff King
2018-01-01 15:26 ` Michael Haggerty

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).