Skip to content

Push results to EOF on large repositories #26

Open

Description

@topikettunen

Hi!

I'm currently working on a small and simple tool for syncing my forks utilizing this library which can be found here: https://github.com/topikettunen/gitsyncr. The tool simply just pulls the latest changes from upstream and then pushes them to my fork.

I stumbled upon this problem when I was trying to push the latest changes from the Linux kernel's upstream to my fork using my tool which then resulted in the following output: https://github.com/topikettunen/gitsyncr/issues/1.

Code in question is:

func pushChanges(url, path string, user user, publicKey *ssh.PublicKeys) {
	r, err := git.PlainOpen(path)
	if err != nil {
		log.Fatal(err)
	}
	pushOpts := pushOpts(url, user, publicKey)
	err = r.Push(&pushOpts)
	if err == git.NoErrAlreadyUpToDate {
		log.Printf("%s already up to date...\n", url)
	} else if err != nil {
		log.Fatal(err)
	}
}

PushOptions used:

if strings.Contains(url, "git://") {
	pushOpts = git.PushOptions{
		RemoteName: "fork",
		Progress: os.Stdout,
	}
} else {
	pushOpts = git.PushOptions{
		RemoteName: "fork",
		Auth: publicKey,
		Progress: os.Stdout,
	}
}

The function didn't seem to have any problems when pushing changes for other my forks, e.g. Kubernetes which is also a quite large repository. But this error arises only with this Linux kernel fork. I was thinking could it be something related to different protocols used, since I used Git protocol for the kernel's upstream and SSH to push to the fork, but after testing with the Linux's GitHub mirror which uses SSH, it resulted in the same error. Although cloning and pulling from the upstream worked for the Linux kernel, only the push failed. This then led me to believe this is something related to large repositories.

Am I doing something wrong or do you know the answer to this?

Activity

  1. mcuadros commented on Apr 23, 2020

    @mcuadros
    Member

    Without reading you project is hard to tell, but assuming is correct since is able to push to another repository, maybe is a bug.

    As always a EOF is hard to tell, maybe it's from the upstream connection maybe it's reading your files. :/

  2. topikettunen commented on Apr 23, 2020

    @topikettunen
    Author

    Yeah, I haven't encountered problems with other repositories.

    Also running Git alone, e.g. git pull upstream master && git push fork master, works fine on this repository, but something happens within this library between the pull and push.

  3. github-actions commented on Sep 29, 2023

    @github-actions

    To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

    This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

    We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

    Thanks for your understanding and cooperation!

  4. added
    stale
    on Sep 29, 2023
  5. st3fan commented on Jun 17, 2024

    @st3fan

    This issue happens for me with the following trace .. i'm pushing a rather large change set over SSH. I'm specifically having this problem with AWS CodeCommit. The same push to another Git hosting service works fine. I'm thinking AWS is less lenient about long running operations that keep the connection idle with no traffic.

    plumbing/protocol/packp/updreq_encode.go:42
    
    ...
    	if req.Packfile != nil {
    		if _, err := io.Copy(w, req.Packfile); err != nil {
    			panic(err)
    			return err
    		}
    
    		return req.Packfile.Close()
    	}
    

    The io.Copy() returns the EOF which makes me think the underlying SSH channel has been closed.

    Full trace:

    github.com/go-git/go-git/v5/plumbing/protocol/packp.(*ReferenceUpdateRequest).Encode(0x140063da0c0, {0x14e29bff0, 0x14002458160})
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/plumbing/protocol/packp/updreq_encode.go:42 +0x190
    github.com/go-git/go-git/v5/plumbing/transport/internal/common.(*session).ReceivePack(0x14002151400, {0x100995800, 0x100ca3c40}, 0x140063da0c0)
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/plumbing/transport/internal/common/common.go:335 +0x39c
    github.com/go-git/go-git/v5.pushHashes({0x100995800, 0x100ca3c40}, {0x100995d10, 0x14002151400}, {0x100998d00, 0x14000380160}, 0x140063da0c0, {0x1400d350000, 0x1d7e6, 0x24199}, ...)
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/remote.go:1476 +0x240
    github.com/go-git/go-git/v5.(*Remote).PushContext(0x14014e869d8, {0x100995800, 0x100ca3c40}, 0x14003f37490)
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/remote.go:231 +0x940
    github.com/go-git/go-git/v5.(*Repository).PushContext(0x140003ae6c0, {0x100995800, 0x100ca3c40}, 0x140001b3490)
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/repository.go:1235 +0x70
    github.com/go-git/go-git/v5.(*Repository).Push(...)
            /Users/stefan/go/src/github.com/example/example/vendor/github.com/go-git/go-git/v5/repository.go:1215
    github.com/st3fan/devbotsxyz/actions/sync-repository.SyncRepositoryAction({0x100995800, 0x100ca3c40}, 0x100ca3c40?, 0x140002566c0, 0x140000ae240?, 0x140000b2708, 0x140000f0780)
            /Users/stefan/go/src/github.com/example/example/actions/sync-repository/main.go:217 +0xb98
    
  6. st3fan commented on Jun 17, 2024

    @st3fan

    @mcuadros is it possible to re-open this issue? i can provide more details if you have specific questions.

  7. st3fan commented on Jun 17, 2024

    @st3fan

    From https://github.com/git/git/blob/master/Documentation/config/uploadpack.txt

    uploadpack.keepAlive::
    	When `upload-pack` has started `pack-objects`, there may be a
    	quiet period while `pack-objects` prepares the pack. Normally
    	it would output progress information, but if `--quiet` was used
    	for the fetch, `pack-objects` will output nothing at all until
    	the pack data begins. Some clients and networks may consider
    	the server to be hung and give up. Setting this option instructs
    	`upload-pack` to send an empty keepalive packet every
    	`uploadpack.keepAlive` seconds. Setting this option to 0
    	disables keepalive packets entirely. The default is 5 seconds.
    

    This sounds like a plausible underlying root cause.

  8. reopened this on Jun 17, 2024
  9. added
    help wanted
    no-autoclose
    and removed
    stale
    on Jun 17, 2024
  10. pjbgf commented on Jun 17, 2024

    @pjbgf
    Member

    @st3fan thanks for looking into it, and at a quick glance it does sound like a plausible root cause. It would be good to understand what that "empty keepalive packet" looks like upstream, and then make that option available potentially via PushOptions.

    Another thing to look at is whether there is any capability that controls such behaviour, so that the server can opt-out of this or is this solely managed by the client side?

  11. ostapkonst commented on Mar 13, 2025

    @ostapkonst

    We encountered a similar issue when pushing changes to a large repository over the SSH protocol. Conducted a small investigation... It appears that the problem arises because a significant amount of time passes between opening the session (newSendPackSession) and actually sending the hash packets (pushHashes), during which the connection manages to close. As the @st3fan above mentioned, in the second version of the Git protocol, the connection is maintained by sending additional packets (0005\1, in git src). For the first version of the protocol, I suggest using two connections instead of one as a draft solution.

    Below is a patch that resolves the issue we encountered in our case:

    --- ./remote.go	2025-01-10 23:23:49.374004600 +1000
    +++ ./remote_hotfix.go	2025-01-10 23:35:23.722924900 +1000
    @@ -113,14 +113,18 @@
     		o.RemoteURL = r.c.URLs[0]
     	}
     
    -	s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.CABundle, o.ProxyOptions)
    -	if err != nil {
    -		return err
    -	}
    +	getAdvertisedReferences := func() (*packp.AdvRefs, error) {
    +		s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.CABundle, o.ProxyOptions)
    +		if err != nil {
    +			return nil, err
    +		}
    +
    +		defer ioutil.CheckClose(s, &err)
     
    -	defer ioutil.CheckClose(s, &err)
    +		return s.AdvertisedReferencesContext(ctx)
    +	}
     
    -	ar, err := s.AdvertisedReferencesContext(ctx)
    +	ar, err := getAdvertisedReferences()
     	if err != nil {
     		return err
     	}
    @@ -219,7 +223,18 @@
     		}
     	}
     
    -	rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar), allDelete)
    +	pushHashesToRepo := func() (*packp.ReportStatus, error) {
    +		s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.CABundle, o.ProxyOptions)
    +		if err != nil {
    +			return nil, err
    +		}
    +
    +		defer ioutil.CheckClose(s, &err)
    +
    +		return pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar), allDelete)
    +	}
    +
    +	rs, err := pushHashesToRepo()
     	if err != nil {
     		return err
     	}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedno-autoclose

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions