Hello Michael,

On 11/23/2011 03:34 AM, Michael Raab wrote:
today I found one more issue related to that topic. When disconnecting more 
than the half of all connected channels of a group connection, my application 
crashed. The reason was that GroupConnection and GroupSockConnection both use 
index based access on internal vectors of sockets and channels. When calling 
erase during disconnect() elements inside these vectors are shifted, which is 
not a good idea. Please find attached a patch that tries to solve that (it 
works for our purposes).

you are correct, there is a problem with the channel <-> index mapping when disconnecting endpoints. Thank you for sending the patch, unfortunately I don't believe it is the correct solution because there are a number of places that use the size of e.g. _selection (getChannelCount()) or _sockets to get the number of connected endpoints. Using erase is fine as long as the channel <-> index mapping is adjusted correctly, see the attached patch.

        Cheers,
                Carsten
Index: Source/Base/Network/Base/OSGGroupConnection.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Base/Network/Base/OSGGroupConnection.cpp,v
retrieving revision 1.1
diff -u -p -r1.1 OSGGroupConnection.cpp
--- Source/Base/Network/Base/OSGGroupConnection.cpp	30 Jan 2004 12:23:26 -0000	1.1
+++ Source/Base/Network/Base/OSGGroupConnection.cpp	23 Nov 2011 17:25:16 -0000
@@ -149,9 +149,10 @@ std::string GroupConnection::getDestinat
 Connection::Channel GroupConnection::newChannelIndex(ChannelIndex index)
 {
     Channel channel;
-    if(_reuseChannel.begin() != _reuseChannel.end())
+
+    if(!_reuseChannel.empty())
     {
-        channel = *(_reuseChannel.begin());
+        channel = _reuseChannel.front();
         _reuseChannel.pop_front();
     }
     else
@@ -159,10 +160,12 @@ Connection::Channel GroupConnection::new
         channel = _channelToIndex.size();
         _channelToIndex.resize(channel+1);
     }
+
     if(index >= _indexToChannel.size())
         _indexToChannel.resize(index+1);
     if(index >= _selection.size())
         _selection.resize(index+1);
+
     // enable selection
     _selection[index] = true;
     // set index to channel mapping
@@ -180,6 +183,16 @@ void GroupConnection::delChannelIndex(Ch
     // erase from indexed arrays
     _selection     .erase(_selection.begin()      + index);
     _indexToChannel.erase(_indexToChannel.begin() + index);
+
+    // adjust channel indices
+    for(UInt32 i = 0; i < _channelToIndex.size(); ++i)
+    {
+        if(_channelToIndex[i] > index)
+            _channelToIndex[i] -= 1;
+    }
+
+    _channelToIndex[channel] = -1;
+
     // move to reuse
     _reuseChannel.push_back(channel);
 }
Index: Source/Base/Network/Socket/OSGGroupSockConnection.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Base/Network/Socket/OSGGroupSockConnection.cpp,v
retrieving revision 1.15
diff -u -p -r1.15 OSGGroupSockConnection.cpp
--- Source/Base/Network/Socket/OSGGroupSockConnection.cpp	5 Sep 2008 08:21:33 -0000	1.15
+++ Source/Base/Network/Socket/OSGGroupSockConnection.cpp	23 Nov 2011 17:25:16 -0000
@@ -122,7 +122,7 @@ GroupConnection::Channel GroupSockConnec
     if(connectSocket(socket,address,destination,timeout))
     {
         channel = newChannelIndex(_sockets.size());
-        _sockets.push_back(socket);
+        _sockets        .push_back(socket);
         _remoteAddresses.push_back(destination);
         _readIndex = 0;
     }
@@ -141,7 +141,8 @@ void GroupSockConnection::disconnect(Cha
     catch(...)
     {
     }
-    _sockets.erase(_sockets.begin() + index);
+    _sockets        .erase(_sockets        .begin() + index);
+    _remoteAddresses.erase(_remoteAddresses.begin() + index);
     delChannelIndex(index);
     _readIndex = 0;
 }
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to