deluge icon indicating copy to clipboard operation
deluge copied to clipboard

[Core] Call wait_for_alert in a thread

Open DjLegolas opened this issue 6 years ago • 11 comments

This spawns a thread in alertmanager to call wait_for_alert in a thread. This reduces latency to deluge responding to events.

Based on #175.

DjLegolas avatar Oct 22 '18 06:10 DjLegolas

I think everything is fixed.

DjLegolas avatar Oct 25 '18 16:10 DjLegolas

This pull request looks good to me. It would be nice to have some better tests for alert manager, as we don't cover much of what has changed. Feel free to follow-up with some expanded tests if you're interested :)

aresch avatar Oct 31 '18 02:10 aresch

Hmm, ok, I'll give it a try. Correct me if I'm wrong, but to fully test AlertManager, I'll need to make libtorrent post some alerts and to handle them correctly. One way is to mock it, and the other is to somehow force is to set an alert. Which is the better way?

DjLegolas avatar Oct 31 '18 17:10 DjLegolas

Considering the time it takes alerts to be posted, sometimes ~0.5s, mocking libtorrent is a better route. Although a lot of tests rely on libtorrent, it's not the best way of unit testing... :)

cas-- avatar Oct 31 '18 18:10 cas--

Hmm, ok, I'll give it a try. Correct me if I'm wrong, but to fully test AlertManager, I'll need to make libtorrent post some alerts and to handle them correctly. One way is to mock it, and the other is to somehow force is to set an alert. Which is the better way?

Yea, you'll want to mock out session.pop_alerts() and session.wait_for_alerts(). You can check out how we did it in spritzle for an idea: https://github.com/spritzle/spritzle/blob/master/spritzle/tests/test_alert.py

aresch avatar Oct 31 '18 19:10 aresch

So I wrote some test units... What do you guys think @aresch @cas--?

DjLegolas avatar Nov 04 '18 19:11 DjLegolas

Any thoughts why this change cases tox -e py3 to fail? I tested it with python 3.5, 3.6, 3.7 and only with 3.7 all tests pass.

DjLegolas avatar Nov 05 '18 19:11 DjLegolas

Rebased and fixed last 2 changes requested by @aresch

DjLegolas avatar Jan 27 '22 01:01 DjLegolas

@DjLegolas I imagine that the segfault in tests is due to https://github.com/arvidn/libtorrent/issues/6437

cas-- avatar Jan 27 '22 08:01 cas--

Saving the segfault job for later use. @cas-- how do you want to handle this? We could try to perform a deep-copy of the alerts

DjLegolas avatar Jan 27 '22 19:01 DjLegolas

I am not sure this is stable, I just had it crash on me as soon as I tested the branch out

I am not willing to merge this while there is the potential for segfaults in alert handling.

cas-- avatar Feb 15 '22 17:02 cas--

@DjLegolas I have merged the changes for component 0745c0eff85ea4e4a3646c454098503ed08c56ff and 25a2b113e290600043338e22b4f116cd2dbf2886 but I am finding that the alertmanager thread changes is increasing the propagation of segfaults due to the alert pointer going out of scope... I will investigate further on how we can workaround the issue.

cas-- avatar Mar 06 '23 22:03 cas--

Thanks @DjLegolas

I applied a refactor to remove the alert copy and avoid segfaults: https://github.com/deluge-torrent/deluge/commit/54d6f502319ea60de6cbe34f1c22e7eed367f1ee

I'm not sure what effect this will have for alert handling so might need to keep an eye on it and revisit if needed.

cas-- avatar Nov 27 '23 15:11 cas--