lidgren / lidgren-network-gen3

Lidgren Network Library
https://groups.google.com/forum/#!forum/lidgren-network-gen3
MIT License
1.19k stars 331 forks source link

NetIncomingMessage.SenderConnection occasionally null #45

Open jbruening opened 8 years ago

jbruening commented 8 years ago

SenderConnection occasionally evaluates to null, and then suddenly isn't

senderconnection

built off c42b885

jbruening commented 8 years ago

More information if it helps:

msg.Data was a valid byte array with 20215 bytes delivery method was UnreliableSequenced LengthBits was 161720

lidgren commented 8 years ago

The code you pasted isn't part of the library... do you get this problem with the samples as well?

jbruening commented 8 years ago

I have a simple program that can reproduce this issue

http://pastebin.com/0Zn8nqXV

Just make a new project with a reference to a build from c42b885

This should also reproduce #43, but it doesn't seem to be. Increasing the time between clients connecting to something like 10 seconds might reproduce it.

jbruening commented 8 years ago

Definitely a threading issue. Using the code in the pastebin, I put a few more variables to peek at the state of the incoming message before breaking.

threading

The type also switched in that image from a Data to an Error, which I'm assuming is the reason for the nulls.

jbruening commented 8 years ago

That commit doesn't seem to entirely fix the problem though.

lidgren commented 8 years ago

Can you verify setting UseMessageRecycling to false suppressed the problem?

jbruening commented 8 years ago

I shouldn't have deleted my previous message, it's definitely still happening -

The program stops working. The server starts getting statuschanged messages that are at the end of their array. out of bounds Attempting to change the position to 0 does not help, as the messages are still constantly received.

lidgren commented 8 years ago

Did you try UseMessageRecycling false? I also advice running in Debug as more checks are made there. I presume you are not manually recycling the message before it's read. I did some extra checks on recycling but was unable to detect any corruption in the library samples.

jbruening commented 8 years ago

yes, that last message is with UseMessageRecycling set to false.

No, I am not manually recycling the message before it's being read. It's still the same program as what is in the pastebin link.

Debug build throws on an assert about it being out of bounds, before it attempts to do the read, but it's still effectively doing the same thing.

The chat example runs fine for me

jbruening commented 8 years ago

This seems to be stemming from the UnreliableSizeBehaviour being set to NormalFragmentation.

lidgren commented 8 years ago

Aha. UnreliableSizeBehaviour.NormalFragmentation is a very suspect feature kept mostly for backwards compability. It should never really be used as it stands right now. I'm hoping to implement fragmentation for unreliable messages better (some kind of timeout for collecting incomplete fragments) some day...