Haivision / srt

Secure, Reliable, Transport
https://www.srtalliance.org
Mozilla Public License 2.0
3.07k stars 840 forks source link

srt-file-transmit loses 99% of data in transfer #645

Closed dnastrain closed 5 years ago

dnastrain commented 5 years ago

Issue seems to coincide with commit 9e48f03 about 6 days ago, that srt-file-transmit no longer works correctly.

Running both Source and Target sides with "-v" reveals data loss -- Source sending 1316 bytes per chunk sent, and the Target receiving 1 byte per chunk sent.

Source-side: sends a file size 134,232 bytes input3.txt

srt-file-transmit.exe -v ./input3.txt srt://:5555
SOURCE type=file, TARGET type=srt
Extract path './input3.txt': directory=C:\Users\dbalma\Projects\srt\bin\Release/. filename=input3.txt
Opening SRT target listener on :5555
Binding a server on :5555 ...
 listen...
Event with status 3

 accept...
 connected.
Target connected (listener)
Upload: 1316 --> 1316
Event with status 5

Upload: 1316 --> 1316
Event with status 5

Upload: 1316 --> 1316
Event with status 5

[...]

Upload: 1316 --> 1316
Event with status 5

File sent
Buffers flushed
SrtCommon: DESTROYING CONNECTION, closing sockets (rt%980186327 ls%-1)...
SrtCommon: ... done.

Target-side: receives file size 100 bytes output3.txt

srt-file-transmit.exe -v srt://127.0.0.1:5555 ./output3.txt
SOURCE type=srt, TARGET type=file
Extract path './output3.txt': directory=C:\Users\dbalma\Projects\srt\bin\Release/. filename=output3.txt
Opening SRT source caller on 127.0.0.1:5555
Connecting to 127.0.0.1:5555
Event with status 5

Source connected (caller), id []
Writing output to [C:\Users\dbalma\Projects\srt\bin\Release/./output3.txt]
Download: --> 1
Event with status 5

Download: --> 1
Event with status 5

Download: --> 1
Event with status 5

[...]

Download: --> 1
Event with status 6

Source disconnected
SrtCommon: DESTROYING CONNECTION, closing sockets (rt%120426075 ls%-1)...
SrtCommon: ... done.

@Howlowck also observed this behavior -- we've reproduced on both Linux and Windows builds this week.

maxsharabayko commented 5 years ago

@dnastrain Thanks for reporting. The issue is with the return value of srt->Read(…). It actually returns true/false, while I was expecting it to return the number of bytes actually read (like srt_recv(s, buf.data(), ::g_buffer_size);, that was previously used instead. Issue introduced by PR #598.

n = src->Read(cfg.chunk_size, buf, out_stats);
if (n == SRT_ERROR)
{
    cerr << "Download: SRT error: " << srt_getlasterror_str() << endl;
    goto exit;
}

if (n == 0)
{
    result = true;
    cerr << "Download COMPLETE.";
    break;
}
zerodefect commented 5 years ago

Is there a way to catch problems like this in future using CI?

maxsharabayko commented 5 years ago

Cool question! :) I am writing a python script that starts two subprocesses of srt-*-transmit, transmits generated data on a local host, and validates the data received. I hope it will work correctly in CI.

maxsharabayko commented 5 years ago

@zerodefect Drafted a PR #663. Feel free to contribute.

zerodefect commented 5 years ago

Brilliant! Been on leave for a number of days, but this looks very promising and a welcome addition!