Skip to content

Commit 023a61e

Browse files
authored
Merge pull request git-lfs#3383 from bk2204/shared-repo-hang
Avoid hang in repos cloned with --shared or --reference
2 parents 5a3e5e9 + ef0410e commit 023a61e

File tree

8 files changed

+79
-19
lines changed

8 files changed

+79
-19
lines changed

commands/command_status.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ func statusCommand(cmd *cobra.Command, args []string) {
3434

3535
scanner, err := lfs.NewPointerScanner()
3636
if err != nil {
37-
scanner.Close()
38-
3937
ExitWithError(err)
4038
}
4139

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/git-lfs/git-lfs
33
require (
44
github.com/ThomsonReutersEikon/go-ntlm v0.0.0-20151030004737-b00ec39bbdd0
55
github.com/alexbrainman/sspi v0.0.0-20180125232955-4729b3d4d858
6-
github.com/git-lfs/gitobj v1.0.0
6+
github.com/git-lfs/gitobj v1.1.0
77
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18
88
github.com/git-lfs/wildmatch v1.0.0
99
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/alexbrainman/sspi v0.0.0-20180125232955-4729b3d4d858 h1:OZQyEhf4Bviyd
44
github.com/alexbrainman/sspi v0.0.0-20180125232955-4729b3d4d858/go.mod h1:976q2ETgjT2snVCf2ZaBnyBbVoPERGjUz+0sofzEfro=
55
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
66
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/git-lfs/gitobj v1.0.0 h1:+tZj++WOWMNTMP3aMJrKel8ogWkN+hRRCGNVUE+UXio=
8-
github.com/git-lfs/gitobj v1.0.0/go.mod h1:EdPNGHVxXe1jTuNXzZT1+CdJCuASoDSLPQuvNOo9nGM=
7+
github.com/git-lfs/gitobj v1.1.0 h1:XRUyk5nKYTWiO8U4cokO5QeoNUNBL8LKS+jXxXZdCTA=
8+
github.com/git-lfs/gitobj v1.1.0/go.mod h1:EdPNGHVxXe1jTuNXzZT1+CdJCuASoDSLPQuvNOo9nGM=
99
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18 h1:7Th0eBA4rT8WJNiM1vppjaIv9W5WJinhpbCJvRJxloI=
1010
github.com/git-lfs/go-netrc v0.0.0-20180525200031-e0e9ca483a18/go.mod h1:70O4NAtvWn1jW8V8V+OKrJJYcxDLTmIozfi2fmSz5SI=
1111
github.com/git-lfs/wildmatch v1.0.0 h1:TKsxqSrEXWj73N4xGcN/ISal8/JJOiAcOv9LH6Zprxw=

lfs/gitscanner_tree.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ func runScanTree(cb GitScannerFoundPointer, ref string, filter *filepathfilter.F
4949
func catFileBatchTree(treeblobs *TreeBlobChannelWrapper) (*PointerChannelWrapper, error) {
5050
scanner, err := NewPointerScanner()
5151
if err != nil {
52-
scanner.Close()
53-
5452
return nil, err
5553
}
5654

5755
pointers := make(chan *WrappedPointer, chanBufSize)
5856
errchan := make(chan error, 10) // Multiple errors possible
5957

6058
go func() {
59+
hasNext := true
6160
for t := range treeblobs.Results {
62-
hasNext := scanner.Scan(t.Sha1)
61+
hasNext = scanner.Scan(t.Sha1)
62+
6363
if p := scanner.Pointer(); p != nil {
6464
p.Name = t.Filename
6565
pointers <- p
@@ -74,10 +74,14 @@ func catFileBatchTree(treeblobs *TreeBlobChannelWrapper) (*PointerChannelWrapper
7474
}
7575
}
7676

77-
// Deal with nested error from incoming treeblobs
78-
err := treeblobs.Wait()
79-
if err != nil {
80-
errchan <- err
77+
// If the scanner quit early, we may still have treeblobs to
78+
// read, so waiting for it to close will cause a deadlock.
79+
if hasNext {
80+
// Deal with nested error from incoming treeblobs
81+
err := treeblobs.Wait()
82+
if err != nil {
83+
errchan <- err
84+
}
8185
}
8286

8387
if err = scanner.Close(); err != nil {

t/t-fetch.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ begin_test "init for fetch tests"
5151
git push origin newbranch
5252
assert_server_object "$reponame" "$b_oid"
5353

54-
# This clone is used for subsequent tests
54+
# These clones are used for subsequent tests
5555
clone_repo "$reponame" clone
56+
git clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared"
5657
)
5758
end_test
5859

@@ -70,6 +71,21 @@ begin_test "fetch"
7071
)
7172
end_test
7273

74+
begin_test "fetch (shared repository)"
75+
(
76+
set -e
77+
cd shared
78+
rm -rf .git/lfs/objects
79+
80+
git lfs fetch 2>&1 | tee fetch.log
81+
! grep "Could not scan" fetch.log
82+
assert_local_object "$contents_oid" 1
83+
84+
git lfs fsck 2>&1 | tee fsck.log
85+
grep "Git LFS fsck OK" fsck.log
86+
)
87+
end_test
88+
7389
begin_test "fetch with remote"
7490
(
7591
set -e

vendor/github.com/git-lfs/gitobj/backend.go

Lines changed: 46 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/git-lfs/gitobj/object_db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ github.com/alexbrainman/sspi
66
github.com/alexbrainman/sspi/ntlm
77
# github.com/davecgh/go-spew v1.1.1
88
github.com/davecgh/go-spew/spew
9-
# github.com/git-lfs/gitobj v1.0.0
9+
# github.com/git-lfs/gitobj v1.1.0
1010
github.com/git-lfs/gitobj
1111
github.com/git-lfs/gitobj/errors
1212
github.com/git-lfs/gitobj/pack

0 commit comments

Comments
 (0)