Opened 9 years ago

Closed 8 years ago

#2738 closed bug (Fixed)

Illegal argument to libtorrent set_max_connections

Reported by: bro Owned by: bro
Priority: minor Milestone: 1.3.13
Component: libtorrent Version: develop
Keywords: Cc: bro


When testing a debug build of libtorrent I noticed that it fails on an assert statement that tests for valid input to the torrent_handle.set_max_connections

Libtorrent docs says that

This must be at least 2. The default is unlimited number of connections. If -1 is given to the function, it means unlimited.

During startup, deluge passes 0 to this function for some of the torrents. Oddly enough, lt actually treats 0 and -1 equally:

if (limit <= 0) limit = (1<<24)-1;

I'm not sure what really happens when passing in 1.

There are two different asserts:

set_max_connections (torrent_handle.cpp)

TORRENT_ASSERT_PRECOND(max_connections >= 2 || max_connections == -1);

set_max_connections (torrent.cpp)

TORRENT_ASSERT(limit >= -1);

This could indicate that it's only a bug in the lt doc and the assert in torrent_handle.cpp, i.e., 1 and 0 are also valid values.

Change History (6)

comment:1 Changed 9 years ago by Cas

I didn't realise you meant a debug libtorrent build, could you clarify it with Arvid and then we can fix it in Deluge.

comment:2 Changed 9 years ago by bro

  • Owner set to bro
  • Status changed from new to assigned

comment:3 Changed 9 years ago by Cas

  • Component changed from Core to libtorrent
  • Milestone changed from Future to 2.0

comment:4 Changed 8 years ago by bro

I opened a libtorrent issue github but we didn't conclude on anything (it seems). Also I believe we may disagree about how asserts should be used.

I guess the simplest solution to fix this in deluge is to ensure that the values passed to libtorrent calls are valid. In the case of set_max_connections, 0 and 1 are not valid input values (according to docs) and gives an assert error when compiled in debug mode. When not in debug mode, 0 is actually treated as -1 and means unlimited. I don't know what happens when passing in 1, but presumably it should be avoided since docs says it must be minimum 2.

comment:5 Changed 8 years ago by bro

  • Cc bro added

Add bro to cc

comment:6 Changed 8 years ago by Cas

  • Milestone changed from 2.0 to 1.3.13
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed in develop [27bf05f2fe7b26988] and 1.3 [a58ce30e7b8d56d789]

Note: See TracTickets for help on using tickets.