springtg / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

Lidgren fails to send any messages after system reaches uptime of 24.8 days or more. #129

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the case when Lidgren has been compiled with IS_STOPWATCH_AVAILABLE set to 
0, the following occurs:

1. Lidgren.Network.NetTime.Now 
(http://code.google.com/p/lidgren-network-gen3/source/browse/trunk/Lidgren.Netwo
rk/NetTime.cs#46) uses Environment.TickCount to report a millisecond-precise 
monotonous time counter.
2. The comment in this member says 'Get number of seconds since the application 
started', but this is incorrect. Environment.TickCount returns time since the 
system start, not the application start.
3. When the system has a long enough uptime, the integer wraps around, and the 
returned double has a negative value.
4. In 
http://code.google.com/p/lidgren-network-gen3/source/browse/trunk/Lidgren.Networ
k/NetPeer.Internal.cs#268 , a delta value is computed. m_lastHeartbeat is 
initialized to 0 on application start, and dnow will have a huge negative 
value. The result is that the delta member also has a large negative value, and 
the if branch to heartbeat processing is never taken.
5. As an overall result, the heartbeat tick is never accessed for the 
connection, and the connection never succeeds in sending out any user-level 
messages (Unreliable, ReliableOrdered, etc.). The built-in library messages 
(Connect, ConnectResponse, ConnectionEstablished, Ping, Pong, Acknowledge) come 
through fine.

A patch to fix this problem is attached. It fixes the NetTime.Now computation 
to be since-application-start and not since-system-start, and treats the 
variable as uint, so that the monotonous counter only wraps around once every 
49.7 days. To account for this wraparound and other potential counter 
monotonity glitches, NetPeer.Internal.cs if () comparison was adapted to take 
the heartbeat branch also if the delta is negative.

Original issue reported on code.google.com by juj...@gmail.com on 23 Aug 2012 at 11:36

Attachments:

GoogleCodeExporter commented 9 years ago
Oh, the .patch was grabbed from another SVN repository which embeds the files 
in Lidgren, so applying the patch directly will not work, but fortunately 
there's only a few lines that were changed.

Original comment by juj...@gmail.com on 23 Aug 2012 at 11:38

GoogleCodeExporter commented 9 years ago
Patched in revision 306, thanks!

Original comment by lidg...@gmail.com on 23 Aug 2012 at 12:55

GoogleCodeExporter commented 9 years ago
Thanks for the quick response!

Original comment by juj...@gmail.com on 24 Aug 2012 at 11:11