Crash when deluge is missing .torrent files (patch)

Suggestions and discussion of future versions
Post Reply
maudib

Crash when deluge is missing .torrent files (patch)

Post by maudib »

Hi,

if I delete a .torrent file from the hdd that deluge have in its list, and then start deluge, I get the following (0.5.7.1):

Code: Select all

no existing Deluge session
Starting new Deluge session...
deluge_core; using libtorrent 0.13.0.0. Compiled with NDEBUG.
Applying preferences
Missing file: /tmp/mytorrentfile.torrent
Traceback (most recent call last):
  File "/usr/bin/deluge", line 136, in <module>
    start_deluge()
  File "/usr/bin/deluge", line 117, in start_deluge
    interface = deluge.interface.DelugeGTK()
  File "/var/lib/python-support/python2.5/deluge/interface.py", line 54, in __init__
    common.CONFIG_DIR)
  File "/var/lib/python-support/python2.5/deluge/core.py", line 276, in __init__
    self.sync(True)
  File "/var/lib/python-support/python2.5/deluge/core.py", line 860, in sync
    for torrent in self.state.torrents:
RuntimeError: dictionary changed size during iteration
I have a small hack-fix-patch that works (but might not be the best way):

Code: Select all

--- /a/core.py	2007-12-01 07:13:05.000000000 +0100
+++ /b/core.py	2007-12-20 17:38:06.000000000 +0100
@@ -856,12 +856,20 @@ Space:") + " " + nice_free)
         ret = None # We return new added unique ID(s), or None
         no_space = False
 
-        # Add torrents to core and unique_IDs
-        for torrent in self.state.torrents:
+
+	# Hack to remove torrents
+	to_delete = []
+	for torrent in self.state.torrents:
             if not os.path.exists(torrent.filename):
+                to_delete.append(torrent)
+	
+	for torrent in to_delete:
                 print "Missing file: %s" % torrent.filename
-                del self.state.torrents[torrent]
-                continue
+		del self.state.torrents[torrent]
+	#End Hack
+
+        # Add torrents to core and unique_IDs
+        for torrent in self.state.torrents:
             if torrent not in self.unique_IDs.values():
 #                print "Adding torrent to core:", torrent.filename, torrent.save_dir, torrent.compact
                 try:
There is probably a couple of more issues like this one in that for loop, this only "fixes" one.
Thanks!
andar
Top Bloke
Top Bloke
Posts: 1050
Joined: Fri Jun 08, 2007 8:38 pm
Location: Victoria, BC
Contact:

Re: Crash when deluge is missing .torrent files (patch)

Post by andar »

This works, but I think the better solution would be to catch the exception loading the .torrent file and then just remove this torrent from the state (or not add it).
Post Reply