diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 36881b607..18f00227b 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -36,6 +36,8 @@ var defaultAnnounceList = [][]string{ } var pieceLength = 100 * 1024 +var ErrTorrentTimedout = errors.New("torrent has timed out") + type Manager struct { persistence *Persistence ensSubscription chan []*ens.VerificationRecord @@ -1929,7 +1931,7 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes m.LogStdout("fetching torrent info", zap.String("magnetlink", magnetlink)) select { case <-timeout: - return nil, errors.New("torrent has timed out") + return nil, ErrTorrentTimedout case <-torrent.GotInfo(): files := torrent.Files() diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 2bd7a7b89..97490b799 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -925,9 +925,18 @@ func (m *Messenger) HandleHistoryArchiveMagnetlinkMessage(state *ReceivedMessage go func() { downloadedArchiveIDs, err := m.communitiesManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink) if err != nil { - log.Println("failed to download history archive data", err) - m.logger.Debug("failed to download history archive data", zap.Error(err)) - return + logMsg := "failed to download history archive data" + if err == communities.ErrTorrentTimedout { + m.communitiesManager.LogStdout("torrent has timed out, trying once more...") + downloadedArchiveIDs, err = m.communitiesManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink) + if err != nil { + m.communitiesManager.LogStdout(logMsg, zap.Error(err)) + return + } + } else { + m.communitiesManager.LogStdout(logMsg, zap.Error(err)) + return + } } messagesToHandle, err := m.communitiesManager.ExtractMessagesFromHistoryArchives(id, downloadedArchiveIDs)