Bug #362

avatar

ArgumentOutOfRangeException in MonoTorrent.Client.ConnectionManager.TryConnect()

Added by Phill Djonov 5403 days ago. Updated 5194 days ago.

Status:Closed Start:03/08/2010
Priority:Normal Due date:
Assigned to:- % Done:

0%

Category:- Spent time: -
Target version:-
Votes: 0

Description

Repro steps:
  1. Add several torrents to a ClientEngine.
  2. Start one.
  3. Wait for it to finish.
  4. Stop it.
  5. Remove it from the ClientEngine.
  6. Start another one. (crash)

It's a little timing sensitive, but not too hard to reproduce. The issue is that TryConnectIndex ends up out past the number of TorrentManagers in the ClientEngine, causing the second loop in ConnectionManager.TryConnect() to blow up. Suggested replacement for both loops:

// Check each torrent manager in turn to see if they have any peers we want to connect to
int count = engine.Torrents.Count;
if( count > 0 ) //gonna do some modulo madness
{
    //wrap the index in case torrents have been
    //removed between the last connect and now (yes, it happens)
    int startIndex = TryConnectIndex % count;

    int i = startIndex;
    do
    {
        if( TryConnect( engine.Torrents[i] ) )
        {
            TryConnectIndex = i + 1;
            break;
        }

        i = (i + 1) % count; //wrap around the list
    } while( i != startIndex ); //ending when we reach the first one we tried to connect to
}

That should spin through the array exactly once, starting at TryConnectIndex, and maintain the old behavior of updating TryConnectIndex to point to the element after the first that successfully made a connection.

History

Updated by Phill Djonov 5380 days ago

avatar

This seems to have been fixed as part of a different change.

(is anyone even watching this site?)

Updated by Alan McGovern 5194 days ago

avatar
  • Status changed from New to Closed

Closing this one then.

Also available in: Atom PDF