libtorrent icon indicating copy to clipboard operation
libtorrent copied to clipboard

Caught internal_error: 'DhtServer::event_write called but both write queues are empty.'

Open Cubittus opened this issue 7 years ago • 3 comments

I've been having rtorrent crashes occasionally just after a download completes. It's not consistent, but I have caught one with a backtrace:

Caught internal_error: 'DhtServer::event_write called but both write queues are empty.'.
---DUMP---
/usr/local/lib64/libtorrent.so.19(_ZN7torrent14internal_error10initializeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x234) [0x7f0fe4c9fd94]
rtorrent(_ZN7torrent14internal_errorC2EPKc+0xa6) [0x451e76]
/usr/local/lib64/libtorrent.so.19(+0xa800d) [0x7f0fe4d1700d]
/usr/local/lib64/libtorrent.so.19(_ZN7torrent9PollEPoll7performEv+0xd1) [0x7f0fe4cb48b1]
/usr/local/lib64/libtorrent.so.19(_ZN7torrent9PollEPoll7do_pollEli+0x5d) [0x7f0fe4cb49cd]
/usr/local/lib64/libtorrent.so.19(_ZN7torrent11thread_base10event_loopEPS0_+0x124) [0x7f0fe4cf9d24]
rtorrent() [0x410d2e]
/lib64/libc.so.6(__libc_start_main+0xf0) [0x7f0fe2788680]
rtorrent() [0x412009]

---END---

I tried replacing the throw internal_error at libtorrent/src/dht/dht_server.cc:899 with a log notice and after a few torrents completed saw it appear in the log. rtorrent continued to function without apparent problem.

It seems that PollEPoll::perform() can sometimes call DhtServer::event_write() when there is nothing on it's queues. There is a TODO comment in that function to that effect at libtorrent/src/torrent/poll_epoll.cc:175. The problem is that DhtServer::event_write() considers such a call to be a fatal internal error.

Here's a trivial patch that essentially ignores the calls and just logs a notice:

diff --git a/src/dht/dht_server.cc b/src/dht/dht_server.cc
index 3bd3654c..93421215 100644
--- a/src/dht/dht_server.cc
+++ b/src/dht/dht_server.cc
@@ -896,7 +896,8 @@ DhtServer::process_queue(packet_queue& queue, uint32_t* quota) {
 void
 DhtServer::event_write() {
   if (m_highQueue.empty() && m_lowQueue.empty())
-    throw internal_error("DhtServer::event_write called but both write queues are empty.");
+         lt_log_print(torrent::LOG_THREAD_NOTICE, "DhtServer::event_write called with both queues empty.", 0);
+  //  throw internal_error("DhtServer::event_write called but both write queues are empty.");

   if (!m_uploadThrottle->is_throttled(&m_uploadNode))
     throw internal_error("DhtServer::event_write called while not in throttle list.");

Cubittus avatar Dec 18 '16 22:12 Cubittus

I've had this problem happen with a tracker experiencing network issues but am unable to reproduce consistently.

jaythomas avatar Jan 02 '19 17:01 jaythomas

Saw the error come up again using rtorrent. It turned out the disk libtorrent was writing to was failing. From an end user point-of-view the message was a bit cryptic but I'd say that's rtorrent's fault for not catching and wrapping the error with something more helpful, not libtorrent's fault.

jaythomas avatar Jan 13 '19 20:01 jaythomas

I get this error regularly. Any update on getting this fixed?

HarryMuscle avatar Jan 09 '22 23:01 HarryMuscle