Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with "broken pipe" #10

Closed
larsmans opened this issue Aug 4, 2014 · 18 comments
Closed

Crash with "broken pipe" #10

larsmans opened this issue Aug 4, 2014 · 18 comments

Comments

@larsmans
Copy link

larsmans commented Aug 4, 2014

While trying to pull changes into a clone of the CPython repo with git fetch origin, I got the following crash:

searching for changes
no changes found
fatal: mark :289218 not declared
fast-import: dumping crash report to .git/fast_import_crash_17220
fatal: Error while running fast-import
Traceback (most recent call last):
  File "/home/larsb/bin/git-remote-hg", line 1322, in <module>
    sys.exit(main(sys.argv))
  File "/home/larsb/bin/git-remote-hg", line 1306, in main
    do_import(parser)
  File "/home/larsb/bin/git-remote-hg", line 721, in do_import
    export_branch(repo, branch)
  File "/home/larsb/bin/git-remote-hg", line 613, in export_branch
    export_ref(repo, branch, 'branches', head)
  File "/home/larsb/bin/git-remote-hg", line 547, in export_ref
    modified_final = export_files(c.filectx(f) for f in modified)
  File "/home/larsb/bin/git-remote-hg", line 288, in export_files
    print d
IOError: [Errno 32] Broken pipe

Crash report fast_import_crash_17220 reads:

fast-import crash report:
    fast-import process: 17220
    parent process     : 17219
    at Mon Aug 4 20:23:06 2014

fatal: mark :289218 not declared

Most Recent Commands Before Crash
---------------------------------
  feature done
  feature import-marks=.git/hg/origin/marks-git
  feature export-marks=.git/hg/origin/marks-git
  feature force
  blob
  mark :289220
  data 196121
  commit refs/hg/origin/branches/default
  mark :289221
  author Tal Einat <[email protected]> 1405518740 +0300
  committer Tal Einat <[email protected]> 1405518740 +0300
  data 66
* from :289218

Active Branch LRU
-----------------
    active_branches = 0 cur, 5 max

  pos  clock name
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Inactive Branches
-----------------
refs/hg/origin/branches/default:
  status      : dirty
  tip commit  : 0000000000000000000000000000000000000000
  old tree    : 0000000000000000000000000000000000000000
  cur tree    : 0000000000000000000000000000000000000000
  commit clock: 0
  last pack   : 


Marks
-----
  exported to .git/hg/origin/marks-git

-------------------
END OF CRASH REPORT

git-remote-hg version is 185852e.

@larsmans larsmans changed the title Crash Crash with "broken pipe" Aug 4, 2014
@fgb
Copy link

fgb commented Aug 4, 2014

This seems to be related to a problem I keep bumping into sporadically. Check the fix from #4.

@larsmans
Copy link
Author

larsmans commented Aug 5, 2014

I got git-marks-check working, and it says "Everything OK" after two runs, but now git fetch crashes with a different error:

searching for changes
no changes found
Traceback (most recent call last):
  File "/home/larsb/bin/git-remote-hg", line 1322, in <module>
    sys.exit(main(sys.argv))
  File "/home/larsb/bin/git-remote-hg", line 1306, in main
    do_import(parser)
  File "/home/larsb/bin/git-remote-hg", line 721, in do_import
    export_branch(repo, branch)
  File "/home/larsb/bin/git-remote-hg", line 613, in export_branch
    export_ref(repo, branch, 'branches', head)
  File "/home/larsb/bin/git-remote-hg", line 557, in export_ref
    print "from :%s" % (rev_to_mark(parents[0]))
  File "/home/larsb/bin/git-remote-hg", line 440, in rev_to_mark
    return marks.from_rev(rev.hex())
  File "/home/larsb/bin/git-remote-hg", line 173, in from_rev
    return self.marks[rev]
KeyError: '77f227624cff2bacfea7e2de5cb73b9b938ce907'
fatal: stream ends early
fast-import: dumping crash report to .git/fast_import_crash_29236
fatal: Error while running fast-import

The new crash report reads:

fast-import crash report:
    fast-import process: 29236
    parent process     : 29235
    at Tue Aug 5 10:54:22 2014

fatal: stream ends early

Most Recent Commands Before Crash
---------------------------------
  feature done
  feature import-marks=.git/hg/origin/marks-git
  feature export-marks=.git/hg/origin/marks-git
  feature force
  blob
  mark :289220
  data 18048
  blob
  mark :289221
  data 24851
  blob
  mark :289222
  data 323442
  blob
  mark :289223
  data 43679
  commit refs/hg/origin/branches/default
  mark :289224
  author Ned Deily <[email protected]> 1405227986 -0700
  committer Ned Deily <[email protected]> 1405227986 -0700
* data 144

Active Branch LRU
-----------------
    active_branches = 1 cur, 5 max

  pos  clock name
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   1)      0 refs/hg/origin/branches/default

Inactive Branches
-----------------
refs/hg/origin/branches/default:
  status      : active loaded
  tip commit  : 30f19e5b983f7aa6974a3b37df0d82627d915c7c
  old tree    : 4b825dc642cb6eb9a060e54bf8d69288fbee4904
  cur tree    : 4b825dc642cb6eb9a060e54bf8d69288fbee4904
  commit clock: 0
  last pack   : 


Marks
-----
  exported to .git/hg/origin/marks-git

-------------------
END OF CRASH REPORT

@nengxu
Copy link

nengxu commented Oct 10, 2014

I was hit by this kind of error the 2nd time today.The first one was about 2 months ago? like @fgb I fixed the first one by re-cloning.

By using the way summarized by @fgb in:

#4

I fixed the 2nd one. Thank you, @fgb and @felipec !

@fgb
Copy link

fgb commented Oct 13, 2014

Glad the summary helped. Here's a direct link for future reference: #4 (comment).

fingolfin added a commit to fingolfin/git-remote-hg that referenced this issue Oct 28, 2014
This doesn't solve the actual issues, but helps mitigate them in many
cases.

I am not completely sure what the "actual" issues are, but one seems to
be that it is apparently relatively easy to end up with a corrupt marks
file (and indeed, the code loading / saving marks does not attempt to be
particular robust).

The other problem hinted at in issue #4 seems to  be when tips in the
remote hg repository change, then this seems to also cause troubles.

See also:
  felipec#4
  felipec#10
@ghostganz
Copy link

I think I just triggered this issue by doing a "git gc" (possibly with the --aggressive option).
Running the fix script and removing the "tips" entries doesn't seem to fix things this time though.

@fingolfin
Copy link
Contributor

As far as I can tell, git-remote-hg does not perform any locking on the marks files, nor are save atomic.

This makes me wonder what happens if one runs two git commands involving git-remote-hg simultaneously. I hope the locking git performs will already take care of git-remote-hg not being run twice in parallel -- for if that ever happens, troubles are likely to ensue.

More worrisome is that writing the marks files is not atomic, thus if this is interrupted for whatever reason, you'd end up with a broken marks file. I do not know if this ever happens, but it might be one cause for the broken marks files people keep running into...

Perhaps one can somehow use more of the git (or mercurial?) infrastructure to make this safer, and attain some resemblance of ACID guarantees. Say by storing the marks in git objects instead of files... But perhaps I am just overcomplicating things....

In any case, as long as there is no reliable way to reproduce this issue, it's very had to do anything about it :-(

@g2p
Copy link

g2p commented Nov 16, 2014

git gc triggers this by calling git prune and killing loose objects.
The steps at #4 (comment) fixed things for me though (and I just had to remove last-note, not tips).

@ghostganz
Copy link

Since git does gc automatically once in a while it is almost inevitable that a repository is going to break and need the git-marks-check dance eventually. Can't this just be built into git-remote-hg itself?

@nengxu
Copy link

nengxu commented Nov 26, 2014

@ghostganz +1

@nengxu
Copy link

nengxu commented Nov 29, 2014

Today this issue hit me again. Very annoying.

@fgb
Copy link

fgb commented Dec 15, 2014

@g2p: You're right that removing the contents of the "tips" dictionary doesn't seem to be necessary. I updated #4 (comment) to reflect this.

@ghostganz: If this could be excited via git garbage collection, we would be seeing issues all the time and the frequency for me can be measured in weeks/months. I tend to modify the repo history regularly on the git end and this hasn't caused any issues I'm aware of.

@fingolfin: +1 for atomic saves. One reliable way I found to reproduce the issue is to synchronize the git and hg repos, then proceed to strip the tip commit from the hg repo. Fetching from git fails with the broken pipe issue because "last-note" points into the ether. In fact, if you make "last-note" point to a non-existent mark you can generate a broken pipe error at will and just reverting the change fixes it.

@Lekensteyn
Copy link

Using stripping history in hg will very likely confuse git-remote-hg, but crashing git-remote-hg is not a great solution either.

Since I have no way to reproduce this, I just made a wrapper around git-remote-hg which will hopefully catch faulty mark files. Please do the same so there is a way to reproduce this:

#!/bin/sh
remote=$1
remotedir="$GIT_DIR/hg/$remote/"
suffix=.$$

for f in \
    "$remotedir/marks-git" \
    "$remotedir/marks-hg" \
; do
    [ ! -e "$f" ] || cp -a "$f" "$f$suffix"
done
git-remote-hg.bin "$@"
ret=$?
if [ $ret -eq 0 ]; then
    rm -f "$remotedir/marks-git$suffix" "$remotedir/marks-hg$suffix"
else
    echo "Stored a marks copy at $remotedir/marks-git$suffix"
fi
exit $ret

fingolfin added a commit to fingolfin/git-remote-hg that referenced this issue Jan 13, 2015
This doesn't solve the actual issues, but helps mitigate them in many
cases.

I am not completely sure what the "actual" issues are, but one seems to
be that it is apparently relatively easy to end up with a corrupt marks
file (and indeed, the code loading / saving marks does not attempt to be
particular robust).

The other problem hinted at in issue #4 seems to  be when tips in the
remote hg repository change, then this seems to also cause troubles.

See also:
  felipec#4
  felipec#10
@apeyser
Copy link

apeyser commented Jan 27, 2015

@fgb: I think the issue may be git prune. It's not the normal garbage collection cycle, but the few that remove long unreferenced objects. You won't see them often -- you'll only see them when you force a prune, or when the prunable objects finally expire, which means this should only be seen on the order of months

@nengxu
Copy link

nengxu commented Feb 25, 2015

Today encountered the same kind of error as @larsmans :

Traceback (most recent call last): File "/usr/bin/git-remote-hg", line 1322, in sys.exit(main(sys.argv)) File "/usr/bin/git-remote-hg", line 1306, in main do_import(parser) File "/usr/bin/git-remote-hg", line 721, in do_import export_branch(repo, branch) File "/usr/bin/git-remote-hg", line 613, in export_branch export_ref(repo, branch, 'branches', head) File "/usr/bin/git-remote-hg", line 557, in export_ref print "from :%s" % (rev_to_mark(parents[0])) File "/usr/bin/git-remote-hg", line 440, in rev_to_mark return marks.from_rev(rev.hex()) File "/usr/bin/git-remote-hg", line 173, in from_rev return self.marks[rev] KeyError: 'dc419a7899b22cf06cd1a60ee0ed3d0021fb45fb' fatal: stream ends early fast-import: dumping crash report to .git/fast_import_crash_7609 fatal: Error while running fast-import

@nengxu
Copy link

nengxu commented Feb 25, 2015

@fgb @g2p I fixed the above "fatal: stream ends early" error by removing the content of the "tips" hash. So this step is still needed in this kind of errors.

@fgb
Copy link

fgb commented Feb 28, 2015

@Lekensteyn: What do you mean there's no way to reproduce the issue? I detail just a way to do so in my #10 (comment) to @fingolfin. There are different triggers for the broken pipe issue that I don't quite understand yet, though, but that can be fixed following the same steps.

@apeyser: Except that this is not on the git side. The only way I found to systematically trigger a broken pipe is to strip the tip commit in hg, as I detail above, which immediately causes the broken pipe. One reason I bump into this issue only sporadically is that I strip a commit from hg on the order of weeks / months.

@nengxu: I bumped into the same issue a month or so ago and ended up adding back the removal of the "tips" contents at the end of step 2 in #4 (comment).

@Lekensteyn
Copy link

@fgb AFAIK my affected repo did not have stripped commits (or else I need to ask my team members), so I thought there is some other issue. If a reproducer for actions other than stripping could be found, it could give some insight.

@felipec
Copy link
Owner

felipec commented May 17, 2016

There are different issues at hand. For the one regarding the missing commits, that's an issue of Git's core. I have the patches that fix the problem. I also found a way to reproduce the issues that happen after that: missing marks, specially for the last_note: issue #56.

@felipec felipec closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants