diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2019-06-05 13:38:33 +0100 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2019-06-05 15:10:35 +0100 |
commit | be74d96c6a665b18284d2a470eefdd1e7cde8527 (patch) | |
tree | 9e72e0ccd5dfd20ac658b716335333f2bce28ffd /deluge | |
parent | 4212bd68001af30a6c7b2bde7ad923d6c6f69b59 (diff) | |
download | deluge-be74d96c6a665b18284d2a470eefdd1e7cde8527.tar.gz deluge-be74d96c6a665b18284d2a470eefdd1e7cde8527.tar.bz2 deluge-be74d96c6a665b18284d2a470eefdd1e7cde8527.zip |
[Core] Copy lt alerts to avoid segfaults
Changes in libtorrent 1.1 mean that alerts are no longer allowed to be
accessed after the next call to pop_alerts.
> It is safe to call pop_alerts from multiple different threads, as
long as the alerts themselves are not accessed once another thread
calls pop_alerts. Doing this requires manual synchronization between
the popping threads.
The solution is to copy the alert attributes and pass that to the
handlers.
Refs: https://github.com/arvidn/libtorrent/issues/2779
#3159
Diffstat (limited to 'deluge')
-rw-r--r-- | deluge/core/alertmanager.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index 04e429ea5..bf9f6b4c5 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -18,6 +18,7 @@ This should typically only be used by the Core. Plugins should utilize the from __future__ import unicode_literals import logging +import types from twisted.internet import reactor @@ -124,7 +125,15 @@ class AlertManager(component.Component): for handler in self.handlers[alert_type]: if log.isEnabledFor(logging.DEBUG): log.debug('Handling alert: %s', alert_type) - self.delayed_calls.append(reactor.callLater(0, handler, alert)) + # Copy alert attributes + alert_copy = types.SimpleNamespace( + **{ + attr: getattr(alert, attr) + for attr in dir(alert) + if not attr.startswith('__') + } + ) + self.delayed_calls.append(reactor.callLater(0, handler, alert_copy)) def set_alert_queue_size(self, queue_size): """Sets the maximum size of the libtorrent alert queue""" |