Opened 10 years ago

Closed 9 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

Description

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 by Calum, 10 years ago

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 by Bro, 9 years ago

Owner: set to Bro
Status: newassigned

comment:3 by Calum, 9 years ago

Component: Corelibtorrent
Milestone: Future2.0

comment:4 by Bro, 9 years ago

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 by Bro, 9 years ago

Cc: Bro added

Add bro to cc

comment:6 by Calum, 9 years ago

Milestone: 2.01.3.13
Resolution: Fixed
Status: assignedclosed

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

Note: See TracTickets for help on using tickets.