Skip to content

Commit

Permalink
fix: torrent stats panic (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Sep 20, 2024
1 parent 5c9bcd3 commit d375046
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion internal/protocol/bt/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (f *Fetcher) doUpload(fromUpload bool) {
continue
}

stats := f.torrent.Stats()
stats := f.torrentStats()
f.data.SeedBytes = lastData.SeedBytes + stats.BytesWrittenData.Int64()

// Check is download complete, if not don't check and stop seeding
Expand Down Expand Up @@ -332,6 +332,17 @@ func (f *Fetcher) doUpload(fromUpload bool) {
}
}

// Get torrent stats maybe panic, see https://github.com/anacrolix/torrent/issues/972
func (f *Fetcher) torrentStats() torrent.TorrentStats {
defer func() {
if r := recover(); r != nil {
// ignore panic
}
}()

return f.torrent.Stats()
}

func (f *Fetcher) UploadedBytes() int64 {
return f.data.SeedBytes
}
Expand Down
4 changes: 2 additions & 2 deletions ui/flutter/lib/app/modules/create/views/create_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ class CreateView extends GetView<CreateController> {
style:
ElevatedButton.styleFrom(shape: const StadiumBorder())
.copyWith(
backgroundColor: WidgetStateProperty.all(
Get.theme.colorScheme.surface)),
backgroundColor: MaterialStateProperty.all(
Get.theme.colorScheme.background)),
onPressed: () {
Get.back();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ class ExtensionView extends GetView<ExtensionController> {
style:
ElevatedButton.styleFrom(shape: const StadiumBorder())
.copyWith(
backgroundColor: WidgetStateProperty.all(
Get.theme.colorScheme.surface)),
backgroundColor: MaterialStateProperty.all(
Get.theme.colorScheme.background)),
onPressed: () {
Get.back();
},
Expand Down
2 changes: 1 addition & 1 deletion ui/flutter/lib/app/views/open_in_new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OpenInNew extends StatelessWidget {
launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
},
style: ElevatedButton.styleFrom(
backgroundColor: Get.theme.colorScheme.surface,
backgroundColor: Get.theme.colorScheme.background,
),
child: Row(
mainAxisSize: MainAxisSize
Expand Down

0 comments on commit d375046

Please sign in to comment.