Skip to content

Commit 132ad46

Browse files
authored
Revert "[perf] Skip cache check if store path exists locally" (#2054)
Reverts #2042 #2042 introduced a bug where adding non-cached packages would fail to add them to the flake on the first attempt. (it would succeed on subsequent attempts after the package is already in the store). The root cause is that `fetchNarInfoStatus` gets called twice per package (even though we cache it and we're not supposed to call it twice). The first call returns `false` because the package is not cached. The second call returns `true` because the package is already in store. This discrepancy essentially causes the package not to appear on the flake at all. When updating state again, the package is already in the nix store so both `fetchNarInfoStatus` calls return true. I think reverting this is best immediate course of action. In follow up we should fix `fetchNarInfoStatus` so it only gets called once (it will improve performance and is more correct). Later on we can think of better way to do #2042. The current implementation is a bit fragile and not 100% consistent with the initial intention of the function, so I'm concerned it can lead to more bugs in the future.
1 parent c198a04 commit 132ad46

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

internal/devpkg/narinfo_cache.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8-
"os"
98
"sync"
109
"time"
1110

1211
"github.com/pkg/errors"
1312
"go.jetpack.io/devbox/internal/boxcli/featureflag"
14-
"go.jetpack.io/devbox/internal/debug"
1513
"go.jetpack.io/devbox/internal/lock"
1614
"go.jetpack.io/devbox/internal/nix"
1715
"golang.org/x/sync/errgroup"
@@ -53,7 +51,6 @@ func (p *Package) IsInBinaryCache() (bool, error) {
5351
// package in the list, and caches the result.
5452
// Callers of IsInBinaryCache may call this function first as a perf-optimization.
5553
func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
56-
defer debug.FunctionTimer().End()
5754
if !featureflag.RemoveNixpkgs.Enabled() {
5855
return nil
5956
}
@@ -148,11 +145,6 @@ func (p *Package) fetchNarInfoStatus(outputName string) (bool, error) {
148145

149146
outputInCache := map[string]bool{} // key = output name, value = in cache
150147
for _, output := range outputs {
151-
// if store path exists locally, then it is equivalent to being in the cache.
152-
if _, err := os.Stat(output.Path); err == nil {
153-
outputInCache[output.Name] = true
154-
continue
155-
}
156148
pathParts := nix.NewStorePathParts(output.Path)
157149
reqURL := BinaryCache + "/" + pathParts.Hash + ".narinfo"
158150
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

0 commit comments

Comments
 (0)