Skip to content

Commit

Permalink
Save stacktrace on torrent crash/panic
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Apr 7, 2024
1 parent a96eed9 commit 74519bd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions torrent/session_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ func crash(torrentID string, msg string) {
}
panic(msg)
}

func (t *torrent) crash(msg string) {
crash(t.id, msg)
}
8 changes: 4 additions & 4 deletions torrent/torrent_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func (t *torrent) handleAllocationDone(al *allocator.Allocator) {
if t.allocator != al {
panic("invalid allocator")
t.crash("invalid allocator")
}
t.allocator = nil

Expand All @@ -21,12 +21,12 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) {
}

if t.files != nil {
panic("files exist")
t.crash("files exist")
}
t.files = al.Files

if t.pieces != nil {
panic("pieces exists")
t.crash("pieces exists")
}
pieces := piece.NewPieces(t.info, t.files)
if len(pieces) == 0 {
Expand All @@ -40,7 +40,7 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) {
}

if t.piecePicker != nil {
panic("piece picker exists")
t.crash("piece picker exists")
}
t.piecePicker = piecepicker.New(t.pieces, t.session.config.EndgameMaxDuplicateDownloads, t.webseedSources)

Expand Down
4 changes: 2 additions & 2 deletions torrent/torrent_messagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (t *torrent) handlePieceMessage(pm peer.PieceMessage) {
pe.StopSnubTimer()

if piece.Writing {
panic("piece is already writing")
t.crash("piece is already writing")
}
piece.Writing = true

Expand Down Expand Up @@ -355,7 +355,7 @@ func (t *torrent) handlePeerMessage(pm peer.Message) {
}
t.handleNewPeers(addrs, peersource.PEX)
default:
panic(fmt.Sprintf("unhandled peer message type: %T", msg))
t.crash(fmt.Sprintf("unhandled peer message type: %T", msg))
}
}

Expand Down
8 changes: 4 additions & 4 deletions torrent/torrent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ func (t *torrent) start() {

func (t *torrent) startVerifier() {
if t.verifier != nil {
panic("verifier exists")
t.crash("verifier exists")
}
if len(t.pieces) == 0 {
panic("zero length pieces")
t.crash("zero length pieces")
}
t.verifier = verifier.New()
go t.verifier.Run(t.pieces, t.verifierProgressC, t.verifierResultC)
}

func (t *torrent) startAllocator() {
if t.allocator != nil {
panic("allocator exists")
t.crash("allocator exists")
}
t.allocator = allocator.New()
go t.allocator.Run(t.info, t.storage, t.allocatorProgressC, t.allocatorResultC)
Expand Down Expand Up @@ -224,7 +224,7 @@ func (t *torrent) startSinglePieceDownloader(pe *peer.Peer) {
}
pd := piecedownloader.New(pi, pe, allowedFast, t.piecePool.Get(int(pi.Length)))
if _, ok := t.pieceDownloaders[pe]; ok {
panic("peer already has a piece downloader")
t.crash("peer already has a piece downloader")
}
t.log.Debugf("requesting piece #%d from peer %s", pi.Index, pe.IP())
t.pieceDownloaders[pe] = pd
Expand Down
2 changes: 1 addition & 1 deletion torrent/torrent_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (t *torrent) getPeers() []Peer {
case peersource.Manual:
source = SourceManual
default:
panic("unhandled peer source")
t.crash("unhandled peer source")
}
p := Peer{
ID: pe.ID,
Expand Down
2 changes: 1 addition & 1 deletion torrent/torrent_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (t *torrent) stop(err error) {
}
}
if t.stoppedEventAnnouncer != nil {
panic("stopped event announcer exists")
t.crash("stopped event announcer exists")
}
t.stoppedEventAnnouncer = announcer.NewStopAnnouncer(trackers, t.announcerFields(), t.session.config.TrackerStopTimeout, t.announcersStoppedC, t.log)

Expand Down
2 changes: 1 addition & 1 deletion torrent/torrent_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (t *torrent) handleVerifyCommand() {

func (t *torrent) handleVerificationDone(ve *verifier.Verifier) {
if t.verifier != ve {
panic("invalid verifier")
t.crash("invalid verifier")
}
t.verifier = nil

Expand Down
2 changes: 1 addition & 1 deletion torrent/torrent_webseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (t *torrent) handleWebseedPieceResult(msg *urldownloader.PieceResult) {
}

if piece.Writing {
panic("piece is already writing")
t.crash("piece is already writing")
}
piece.Writing = true

Expand Down
4 changes: 2 additions & 2 deletions torrent/torrent_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *torrent) handlePieceWriteDone(pw *piecewriter.PieceWriter) {
t.log.Debugln("received corrupt piece from webseed", src.URL)
t.disableSource(src.URL, errors.New("corrupt piece"), false)
default:
panic("unhandled piece source")
t.crash("unhandled piece source")
}
t.startPieceDownloaders()
return
Expand All @@ -41,7 +41,7 @@ func (t *torrent) handlePieceWriteDone(pw *piecewriter.PieceWriter) {

pw.Piece.Done = true
if t.bitfield.Test(pw.Piece.Index) {
panic(fmt.Sprintf("already have the piece #%d", pw.Piece.Index))
t.crash(fmt.Sprintf("already have the piece #%d", pw.Piece.Index))
}
t.mBitfield.Lock()
t.bitfield.Set(pw.Piece.Index)
Expand Down

0 comments on commit 74519bd

Please sign in to comment.