Bug 128567 - [PATCH]: crash due to uncaught exception while trying to resolve missing files at startup.
Summary: [PATCH]: crash due to uncaught exception while trying to resolve missing file...
Status: RESOLVED FIXED
Alias: None
Product: ktorrent
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: Joris Guisson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-03 15:51 UTC by Jonas Widarsson
Modified: 2006-07-21 01:42 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
adds a try - catch statement and displays a KMessageBox::error (2.24 KB, patch)
2006-06-03 15:53 UTC, Jonas Widarsson
Details
backtrace when answering "no" (5.06 KB, application/octet-stream)
2006-07-21 01:23 UTC, Niek Beernink
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Widarsson 2006-06-03 15:51:44 UTC
Version:            svn://anonsvn.kde.org/home/kde/trunk/extragear/network/ktorrent (using KDE KDE 3.5.3)
Installed from:    Compiled From Sources

I sometimes chose to dowload torrents to a USB-disk.
When it is not connected, ktorrent obvoiusly can't work with them.
Ktorrent throws an Error from fileops.cpp that unwinds the whole application if the path is unaccessible, regardless of what I select in that dialog that comes up in KTorrentCore::aboutToBeStarted():

"Several data files of the torrent \"%1\" are missing, do you want to recreate them, or do you want to not download them ?"

So here's a patch to catch that exception. I don't know if it makes things worse. Probably there should be more actions taken to inform ktorrent that those torrents are put to sleep for a sensible time.

This patch doesn't do that at all. I just caught the exception without doing anything beyond that.

I don't know right now if there's any particular freeze going on for ktorrent.
And, also, this is my first code contribution to the KDE project. 
Please be strict and tell me to fix things if I did anything wrong.

Will attach patch in a minute.

URL: svn://anonsvn.kde.org/home/kde/trunk/extragear/network/ktorrent
Revision: 547745
Comment 1 Jonas Widarsson 2006-06-03 15:53:06 UTC
Created attachment 16445 [details]
adds a try - catch statement and displays a KMessageBox::error
Comment 2 Joris Guisson 2006-06-03 16:50:32 UTC
I'm gonna deal with this in a different way and on a different place.
Comment 3 Joris Guisson 2006-06-03 16:54:24 UTC
SVN commit 547838 by guisson:

Fixed bug with uncaught exception during startup of torrent.

BUG: 128567



 M  +35 -8     queuemanager.cpp  
 M  +11 -1     torrentcontrol.cpp  


--- trunk/extragear/network/ktorrent/libktorrent/torrent/queuemanager.cpp #547837:547838
@@ -162,18 +162,26 @@
 		while (i != downloads.end())
 		{
 			kt::TorrentInterface* tc = *i;
+			const TorrentStats & s = tc->getStats();
 			if (tc->getStats().running)
 			{
-				if(type >= 3)
-					tc->stop(true);
-				else
+				try
 				{
-					if( (tc->getStats().completed && type == 2) || (!tc->getStats().completed && type == 1) )
+					if(type >= 3)
 						tc->stop(true);
+					else if( (s.completed && type == 2) || (!s.completed && type == 1) )
+						tc->stop(true);
 				}
+				catch (bt::Error & err)
+				{
+					QString msg =
+							i18n("Error stopping torrent %1 : %2")
+							.arg(s.torrent_name).arg(err.toString());
+					KMessageBox::error(0,msg,i18n("Error"));
+				}
 			}
 			else //if torrent is not running but it is queued we need to make it user controlled
-				if( (tc->getStats().completed && type == 2) || (!tc->getStats().completed && type == 1) || (type == 3) )
+				if( (s.completed && type == 2) || (!s.completed && type == 1) || (type == 3) )
 					tc->setPriority(0); 
 			i++;
 		}
@@ -441,8 +449,17 @@
 			{
 				TorrentInterface* tc = *it;
 				const TorrentStats & s = tc->getStats();
-				
-				tc->start();
+				try
+				{
+					tc->start();
+				}
+				catch (bt::Error & err)
+				{
+					QString msg =
+							i18n("Error starting torrent %1 : %2")
+							.arg(s.torrent_name).arg(err.toString());
+					KMessageBox::error(0,msg,i18n("Error"));
+				}
 			}
 			
 			delete paused_torrents;
@@ -461,7 +478,17 @@
 				if(s.running)
 				{
 					paused_torrents->append(tc);
-					tc->stop(false);
+					try
+					{
+						tc->stop(false);
+					}
+					catch (bt::Error & err)
+					{
+						QString msg =
+								i18n("Error stopping torrent %1 : %2")
+								.arg(s.torrent_name).arg(err.toString());
+						KMessageBox::error(0,msg,i18n("Error"));
+					}
 				}
 			}
 		}
--- trunk/extragear/network/ktorrent/libktorrent/torrent/torrentcontrol.cpp #547837:547838
@@ -233,10 +233,20 @@
 		if (stats.running)
 			return;
 
-		aboutToBeStarted(this);
 		stats.stopped_by_error = false;
 		io_error = false;
+		try
+		{
+			aboutToBeStarted(this);
+		}
+		catch (Error & err)
+		{
+			// something went wrong when files were recreated, set error and rethrow
+			onIOError(err.toString());
+			throw;
+		}
 		
+		
 		// if the torrent has DHT nodes add them as potential peers to the PeerManager
 		if (tor->getNumDHTNodes() > 0)
 		{
Comment 4 Jonas Widarsson 2006-06-03 17:07:17 UTC
ok, just to inform you, now it crashes again.


Using host libthread_db library "/lib/libthread_db.so.1".
`system-supplied DSO at 0xffffe000' has disappeared; keeping its symbols.
[Thread debugging using libthread_db enabled]
[New Thread 16384 (LWP 20063)]
[KCrash handler]
#6  0xb66ea3e1 in kill () from /lib/libc.so.6
#7  0xb69d9131 in pthread_kill () from /lib/libpthread.so.0
#8  0xb69d94ab in raise () from /lib/libpthread.so.0
#9  0xb66ea174 in raise () from /lib/libc.so.6
#10 0xb66eb64d in abort () from /lib/libc.so.6
#11 0xb688cd97 in __cxa_call_unexpected ()
   from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libstdc++.so.5
#12 0xb688cdd4 in std::terminate ()
   from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libstdc++.so.5
#13 0xb688cf46 in __cxa_throw ()
   from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/libstdc++.so.5
#14 0xb7e0f529 in bt::Touch (url=@0xbfc055e0, nothrow=false)
    at /home/jonas/src/ktorrent-svn/libktorrent/util/fileops.cpp:215
#15 0xb7e55920 in bt::MultiFileCache::touch (this=0x84430f8, fpath=
      {static null = {static null = <same as static member of an already seen type>, d = 0x80c0e00, static shared_null = 0x80c0e00}, d = 0x8483fd8, static shared_null = 0x80c0e00}, dnd=false)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/multifilecache.cpp:178
#16 0xb7e553ab in bt::MultiFileCache::create (this=0x84430f8)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/multifilecache.cpp:144
#17 0xb7e1fa4c in bt::ChunkManager::createFiles (this=0x84833e0)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/chunkmanager.cpp:203
#18 0xb7e21eed in bt::ChunkManager::dndMissingFiles (this=0x84833e0)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/chunkmanager.cpp:841
#19 0xb7e3bcd7 in bt::TorrentControl::dndMissingFiles (this=0x843a058)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/torrentcontrol.cpp:1131
#20 0x08077ba6 in KTorrentCore::aboutToBeStarted (this=0x8289d40, 
    tc=0x843a058)
    at /home/jonas/src/ktorrent-svn/apps/ktorrent/ktorrentcore.cpp:775
#21 0x0807866b in KTorrentCore::qt_invoke (this=0x8289d40, _id=9, 
    _o=0xbfc058e0) at ktorrentcore.moc:233
#22 0xb6e62545 in QObject::activate_signal (this=0x843a058, clist=0x8483bb8, 
    o=0xbfc058e0) at qobject.cpp:2356
#23 0xb7e94866 in kt::TorrentInterface::aboutToBeStarted (this=0x843a058, 
    t0=0x843a058) at torrentinterface.moc:174
#24 0xb7e35f04 in bt::TorrentControl::start (this=0x843a058)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/torrentcontrol.cpp:240
#25 0xb7e6a78a in bt::QueueManager::start (this=0x832d4c8, tc=0x843a058, 
    user=true)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/queuemanager.cpp:107
#26 0xb7e6b9b1 in bt::QueueManager::orderQueue (this=0x832d4c8)
    at /home/jonas/src/ktorrent-svn/libktorrent/torrent/queuemanager.cpp:398
#27 0x08075b79 in KTorrentCore::loadTorrents (this=0x8289d40)
    at /home/jonas/src/ktorrent-svn/apps/ktorrent/ktorrentcore.cpp:304
#28 0x08061f70 in KTorrent (this=0x80cbff0)
    at /home/jonas/src/ktorrent-svn/apps/ktorrent/ktorrent.cpp:195
#29 0x0807c734 in KTorrentApp::newInstance (this=0xbfc065e0)
    at /home/jonas/src/ktorrent-svn/apps/ktorrent/ktorrentapp.cpp:66
#30 0xb75ab308 in KUniqueApplication::processDelayed (this=0xbfc065e0)
    at /home/jonas/kdesvn/kdelibs/kdecore/kuniqueapplication.cpp:444
#31 0xb75ab74c in KUniqueApplication::qt_invoke (this=0xbfc065e0, _id=18, 
    _o=0x0) at kuniqueapplication.moc:86
#32 0x0807c9f5 in KTorrentApp::qt_invoke (this=0xbfc065e0, _id=18, 
    _o=0xbfc06010) at ktorrentapp.moc:77
#33 0xb6e62545 in QObject::activate_signal (this=0x82324d8, clist=0x81d4d58, 
    o=0xbfc06010) at qobject.cpp:2356
#34 0xb71cb663 in QSignal::signal (this=0x82324d8, t0=@0x8232500)
    at moc_qsignal.cpp:100
#35 0xb6e7fad2 in QSignal::activate (this=0x82324d8) at qsignal.cpp:212
#36 0xb6e87438 in QSingleShotTimer::event (this=0x82324b0) at qtimer.cpp:286
#37 0xb6dfe7a7 in QApplication::internalNotify (this=0xbfc065e0, 
    receiver=0x82324b0, e=0xbfc06340) at qapplication.cpp:2635
#38 0xb6dfdcde in QApplication::notify (this=0xbfc065e0, receiver=0x82324b0, 
    e=0xbfc06340) at qapplication.cpp:2358
#39 0xb74fddfd in KApplication::notify (this=0xbfc065e0, receiver=0x82324b0, 
    event=0xbfc06340)
    at /home/jonas/kdesvn/kdelibs/kdecore/kapplication.cpp:550
#40 0xb7d380a3 in QApplication::sendEvent (receiver=0x0, event=0x6)
    at qapplication.h:496
#41 0xb6deceae in QEventLoop::activateTimers (this=0x81d4eb8)
    at qeventloop_unix.cpp:556
#42 0xb6da3ca1 in QEventLoop::processEvents (this=0x81d4eb8, flags=4)
    at qeventloop_x11.cpp:389
#43 0xb6e12dfd in QEventLoop::enterLoop (this=0x81d4eb8) at qeventloop.cpp:198
#44 0xb6e12d16 in QEventLoop::exec (this=0x81d4eb8) at qeventloop.cpp:145
#45 0xb6dfe913 in QApplication::exec (this=0xbfc065e0)
    at qapplication.cpp:2758
#46 0x0805fe0d in main (argc=7, argv=0xbfc06764)
    at /home/jonas/src/ktorrent-svn/apps/ktorrent/main.cpp:113
Comment 5 Joris Guisson 2006-06-03 19:26:58 UTC
Are you sure you have the latest ? It should eventually get caught in queuemanager.cpp around line 107 (#25 in the backtrace)
Comment 6 Jonas Widarsson 2006-06-03 23:17:47 UTC
Yes I am sure, I have revision 547889

I believe the problem is that the exception is thrown from #14 which is inside a slot #20 KTorrentCore::aboutToBeStarted.
Qt3 isn't compiled with exceptions here, and from all I've heard on kde-devel this is normal. This means the exception will never reach the point you want it to be catched at. It just aborts here.
Comment 7 Joris Guisson 2006-06-04 10:04:20 UTC
Crap, I was hoping it would work even if Qt was compiled without exception support.
Comment 8 Joris Guisson 2006-06-04 10:40:01 UTC
SVN commit 547968 by guisson:

Catch exceptions at a different place, apparently Qt without exception support will make exceptions not work when we hit a stack frame with Qt code.

BUG: 128567



 M  +35 -12    ktorrentcore.cpp  


--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrentcore.cpp #547967:547968
@@ -756,35 +756,58 @@
 void KTorrentCore::aboutToBeStarted(kt::TorrentInterface* tc)
 {
 	QStringList missing;
-	if (tc->hasMissingFiles(missing))
+	if (!tc->hasMissingFiles(missing))
+		return;
+	
+	
+	if (tc->getStats().multi_file_torrent)
 	{
-		if (tc->getStats().multi_file_torrent)
+		QString msg = i18n("Several data files of the torrent \"%1\" are missing, do you want to recreate them, or do you want to not download them ?").arg(tc->getStats().torrent_name);
+					
+		int ret = KMessageBox::warningYesNoList(0,msg,missing,QString::null,
+				KGuiItem(i18n("Recreate")),KGuiItem(i18n("Do not download")));
+		if (ret == KMessageBox::Yes)
 		{
-			QString msg = i18n("Several data files of the torrent \"%1\" are missing, do you want to recreate them, or do you want to not download them ?").arg(tc->getStats().torrent_name);
-					
-			int ret = KMessageBox::warningYesNoList(0,msg,missing,QString::null,
-					KGuiItem(i18n("Recreate")),KGuiItem(i18n("Do not download")));
-			if (ret == KMessageBox::Yes)
+			try
 			{
 				// recreate them
 				tc->recreateMissingFiles();
 			}
-			else
+			catch (bt::Error & e)
 			{
+				KMessageBox::error(0,i18n("Cannot recreate missing files : %1").arg(e.toString()));
+			}
+		}
+		else
+		{
+			try
+			{
 				// mark them as do not download
 				tc->dndMissingFiles();
 			}
+			catch (bt::Error & e)
+			{
+				KMessageBox::error(0,i18n("Cannot deselect missing files : %1").arg(e.toString()));
+			}
 		}
-		else
+	}
+	else
+	{
+		QString msg = i18n("The file where the data is saved of the torrent \"%1\" is missing, do you want to recreate it ?").arg(tc->getStats().torrent_name);
+		int ret = KMessageBox::warningYesNo(0,msg);
+		if (ret == KMessageBox::Yes)
 		{
-			QString msg = i18n("The file where the data is saved of the torrent \"%1\" is missing, do you want to recreate it ?").arg(tc->getStats().torrent_name);
-			int ret = KMessageBox::warningYesNo(0,msg);
-			if (ret == KMessageBox::Yes)
+			try
 			{
 				tc->recreateMissingFiles();
 			}
+			catch (bt::Error & e)
+			{
+				KMessageBox::error(0,i18n("Cannot recreate data file : %1").arg(e.toString()));
+			}
 		}
 	}
+	
 }
 
 void KTorrentCore::connectSignals(kt::TorrentInterface* tc)
Comment 9 Niek Beernink 2006-07-21 01:23:00 UTC
Created attachment 17050 [details]
backtrace when answering "no"

I'm using Ktorrent 2.0rc1, KDE 3.5.3. I am able to consistently crash Ktorrent
by doing the following;

1. Download a file.
2. Remove file using anything but Ktorrent. (konqueror for example)
3. Restart the Ktorrent.
4. You get a dialog asking if you want to recreate the file. If answered "no"
the application crashes. (If answered yes, the file seems to be properly
re-created.)
Comment 10 Niek Beernink 2006-07-21 01:42:07 UTC
I decided that this might be a seperate bug on it's own. Filed here; http://bugs.kde.org/show_bug.cgi?id=131142