paullouisageneau / libdatachannel

C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets
https://libdatachannel.org/
Mozilla Public License 2.0
1.73k stars 353 forks source link

There is a chance of package lost in datachannel #1160

Open BartolomeyKant opened 4 months ago

BartolomeyKant commented 4 months ago

I am working on application with functionality sending files between peers and it uses libdatachannel on both side. File breaks into chunks by 512 Kb and sent to datachannel one by one. Receiver side collect all chunks back into file until chunk with EOF flag is received. And sometimes file is corrupted. After a few days of investigation I found out that datachannel may lost packages, and It's also true for localhost p2p connection.

Datachannel created with

reliability.type = rtc::Reliability::Type::Reliable;
reliability.unordered = false;
reliability.rexmit = 0;

For investigation I created two counters for sender and receiver sides and send sender's counter with data packet. If packet lost i can see it by matching counters. It's quite difficult to reproduce, I think it's 1/10000 packets chance.

Also I collect Debug logs and there was no errors or any messages about data loss. I am trying to reproduce this error with verbose logs but still without luck.

My question is. Does such datachannel settings guarantee data transmitting reliability? I am using libdatachannel v0.18. Maybe such error was fixed in newer version?

voluntas commented 4 months ago

reliability.unordered = false; reliability.rexmit = 0;

This configuration means that DataChannel does not retransmit nor ensure the order of packets. Therefore, if packets are lost for some reason, they will not be resent, which naturally means there is a possibility of packet loss.

Is the issue here that packet loss is occurring on the localhost?

paullouisageneau commented 4 months ago

Reliable data channels are guaranteed not to lose messages. Could you please share code that reproduces the issue?

You should definitely test with a newer version since 0.18 is more than one year old and there have been two major releases since then.

@voluntas The data channel is reliable and ordered here, this is the legacy reliability API in 0.18, rexmit is ignored when type = Type::Reliable and unordered = false means ordered.