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

Fixed: incorrect waiting for timeout in blocking-but-timeout mode send/receive functions #1057

Merged

Conversation

ethouris
Copy link
Collaborator

@ethouris ethouris commented Jan 9, 2020

This fixes the bug that has been introduced with timeout waiting in blocking mode with timeout setup for sending and receiving.

BEFORE: If the timeout was set up, then the CV waiting function was waiting for the time set up as timeout since the moment when the call is to be made - as it was in the while loop, it means that in case of spurious signals (or meaning something else), which caused the conditions to be re-checked and possibly waiting loop re-entered, the next waiting call started to wait again for the time of timeout since the moment the loop was reentered, not since the moment when the sending/receiving function was called.

EXAMPLE PROBLEM:

  1. The function enters at 10:12:16.000500
  2. Timeout is 2 seconds.
  3. The data are not ready, the function enters the while loop and waiting on a CV up to timeout=2s
  4. After 1.5 second the signal was issued on this CV.
  5. The signal happens to be spurious - at least the "data ready or connection broken" condition is not satisfied. The loop is then continued.
  6. By continuing the loop, the waiting on a CV is done, again, up to timeout=2s

Result: The function is waiting this time for 3.5s, while according to the configuration it should return with EAGAIN after 2s.

FIX: In point 6, waiting is done not for a relative time, but up to the given fixed point in time, which is calculated in the beginning as the function entrance time plus the configured timeout. So, in this case, as the fixed timeout timepoint is precalculated, in this case it would be distant by 0.5s from now, so it will exit after 0.5s, effectively 2s since the function entrance.

@ethouris ethouris added Impact: Heavy [core] Area: Changes in SRT library core Priority: High Type: Bug Indicates an unexpected problem or unintended behavior labels Jan 9, 2020
@ethouris ethouris added this to the v1.5.0 milestone Jan 9, 2020
srtcore/core.cpp Show resolved Hide resolved
srtcore/core.cpp Show resolved Hide resolved
Copy link
Collaborator

@maxsharabayko maxsharabayko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all good.
wait_until() returns false on timeout, and true if signaled or spurious.
On timeout can break the while loop due to the expiry time is reached.

@maxsharabayko maxsharabayko merged commit 712119f into Haivision:master Jan 23, 2020
ethouris pushed a commit to ethouris/srt that referenced this pull request Jan 24, 2020
@mbakholdina mbakholdina modified the milestones: v1.5.0, v1.4.2 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Priority: High Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants