Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate packets with reliable_unordered #222

Closed
Ploppz opened this issue Jul 30, 2019 · 5 comments
Closed

Duplicate packets with reliable_unordered #222

Ploppz opened this issue Jul 30, 2019 · 5 comments

Comments

@Ploppz
Copy link
Contributor

Ploppz commented Jul 30, 2019

In my game I noticed this bug where packets were sometimes received twice or even more. Right now I'm struggling with a packet getting repeated indefinitely and hope that this is related to this issue.

I managed to reproduce the bug in a minimal test case, attached. It only happens under certain conditions; I could only summon the bug when the communicating parts kept sending some other packets (unreliable and reliable_unordered). That is, I could only reproduce it when I added those additional packet streams.
The Join message is received twice at the server, whereas according to the guarantees of reliable_unordered, it should only be received once.

minimal_test_case.zip

@TimonPost
Copy link
Owner

I can confirm this, I did some research but can not directly find the golden key to figure out why this is happening. I can say the following:

  1. After 36 loops the client, sents or the server just receives the other join packet. This will not be affected by sleep duration or whatsoever.
    for _ in 0..36 {
        client_update(&mut client, srv_addr);
        // std::thread::sleep(std::time::Duration::new(0, 8_000_000));
        server_update(&mut server, cli_addr);
        std::thread::sleep(std::time::Duration::from_millis(10));
    }
  1. The problem is highly withing reliable unordered. When disabling the sending of a reliable unordered packet in the server update method, we won't see a double join even happening.

My guess it that it might stick around in the acknowledgment buffer @jstnlef ? I am able to test that in a later stage.

@kstrafe
Copy link
Contributor

kstrafe commented Aug 12, 2019

The acknowledgement buffer looks fine @TimonPost. @Ploppz the packet gets re-sent because the initial join message assumes (by being reliable) that the recipient already has the client added to its connection table. Because it does not, the packet's sequence number is not stored on the server. The server sends a message back to the client (thus adding it to the connection table), however, this message back doesn't contain the bitfield trigger from the initial message because the server was unable to remember it (because of the DoS protection).

Solution: Use unreliable as the first message, then reply with a reliable message.

@TimonPost
Copy link
Owner

TimonPost commented Aug 17, 2019

I can 'acknowledge' that there is nothing wrong with the behavior of laminar in this case. The problem is that you first have to make sure that the client sents a packet to the server, whereafter the server sents a packet back to the client. When you do not do this, the server will never register the client as a connection. As @BourgondAries said, make sure you have an initial packet, and that the server reacts to that initial packet by sending a packet back to the client.

I don't like this approach very much and is a bit confusing, for now, we should definitely write it in our documentation somewhere because those are the issues a user of the library will not be able to just guess by looking at the API. I'll update my PR: #219 and merge that.

I'll close this issue for now, if you have more questions feel free to ask them.

@Ploppz
Copy link
Contributor Author

Ploppz commented Aug 18, 2019

Thank you both for the explanation.
I do think it would be nice if laminar could hide this from the user, but I don't know how much that would take.

@TimonPost
Copy link
Owner

Totaly true, this will be done with #156, which will is on my schedule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants