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

LaunchManyCore fails to produce notification on torrent completion #3719

Closed
ichorid opened this issue Jul 6, 2018 · 10 comments
Closed

LaunchManyCore fails to produce notification on torrent completion #3719

ichorid opened this issue Jul 6, 2018 · 10 comments
Assignees

Comments

@ichorid
Copy link
Contributor

ichorid commented Jul 6, 2018

If a download takes less than a second to complete, sesscb_states_callback fails to produce the notification on torrent finish.
It happens because new_active_downloads only gets new entries if their status is DLSTATUS_DOWNLOADING:

if state == DLSTATUS_DOWNLOADING:
new_active_downloads.append(safename)
elif state == DLSTATUS_STOPPED_ON_ERROR:
self._logger.error("Error during download: %s", repr(ds.get_error()))
if self.download_exists(tdef.get_infohash()):
self.get_download(tdef.get_infohash()).stop()
self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, tdef.get_infohash(), repr(ds.get_error()))
elif state == DLSTATUS_SEEDING:
seeding_download_list.append({u'infohash': tdef.get_infohash(),
u'download': download})
if safename in self.previous_active_downloads:
self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, tdef.get_infohash(), safename)
do_checkpoint = True
elif download.get_hops() == 0 and download.get_safe_seeding():
# Re-add the download with anonymity enabled
hops = self.session.config.get_default_number_hops()
self.update_download_hops(download, hops)
self.previous_active_downloads = new_active_downloads

This makes notification fail for corner cases, like unit tests.

@ichorid ichorid self-assigned this Jul 6, 2018
@devos50
Copy link
Contributor

devos50 commented Jul 7, 2018

Nice find! Certainly an edge case. I guess it's not hard to reproduce this with a unit test and fix it? 👍

@qstokkink
Copy link
Contributor

qstokkink commented Jul 8, 2018

Adding the download to self.previous_active_downloads in add() should fix this I think.

Also, I just noticed self.previous_active_downloads identifies torrents by name and not by infohash. That's quite a brittle design.

@ichorid
Copy link
Contributor Author

ichorid commented Jul 9, 2018

After pondering on this for a few hours I can say that it is impossible to fix this problem correctly without refactoring the libtorrent wrapper.

@qstokkink
Copy link
Contributor

Related to #3418

@qstokkink
Copy link
Contributor

I printed the LibTorrent alerts:

CRITICAL 1531146077.61    LibtorrentDownloadImpl:500  (root)  state_changed_alert: ubuntukylin-17.10-desktop-amd64.iso: state changed to: downloading
CRITICAL 1531146077.61    LibtorrentDownloadImpl:500  (root)  torrent_checked_alert: ubuntukylin-17.10-desktop-amd64.iso checked
CRITICAL 1531146077.62    LibtorrentDownloadImpl:500  (root)  state_changed_alert: ubuntukylin-17.10-desktop-amd64.iso: state changed to: finished
CRITICAL 1531146077.62    LibtorrentDownloadImpl:500  (root)  torrent_finished_alert: ubuntukylin-17.10-desktop-amd64.iso torrent finished downloading
CRITICAL 1531146077.62    LibtorrentDownloadImpl:500  (root)  state_changed_alert: ubuntukylin-17.10-desktop-amd64.iso: state changed to: seeding

We need the first state change downloading/finished (state_changed_alert) after the checked alert (torrent_checked_alert).

@qstokkink
Copy link
Contributor

This seems like it will be fixed in #3775, so I will mark this as completed with AllChannel2.0.

@ichorid
Copy link
Contributor Author

ichorid commented Aug 13, 2018

@qstokkink, I used a different mechanism there, so it is not fixed. This will be fixed with redesign of Libtorrent wrapper, so it should stay opened as a reminder.

@devos50
Copy link
Contributor

devos50 commented Nov 19, 2018

@ichorid we addressed this already with the finished callback in the LibtorrentDownloadImpl itself right?

@ichorid
Copy link
Contributor Author

ichorid commented Feb 23, 2019

Solved by #4090

@ichorid ichorid closed this as completed Feb 23, 2019
@ichorid
Copy link
Contributor Author

ichorid commented Feb 23, 2019

In fact, this is only solved for GigaChannels, because we now don't rely on triggers, but instead schedule periodic channels DB consistency checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants