Skip to content

Commit

Permalink
Added CUDT::breakAsUnstable()
Browse files Browse the repository at this point in the history
Removed unused sendBackup_CheckRunningLinkStable

New connection error: broken as unstable
  • Loading branch information
maxsharabayko committed May 5, 2021
1 parent 810da5d commit 58ffe25
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 46 deletions.
10 changes: 5 additions & 5 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ using namespace std;
using namespace srt;
using namespace srt::sync;
using namespace srt_logging;
using namespace srt;

CUDTUnited CUDT::s_UDTUnited;

Expand Down Expand Up @@ -249,6 +248,7 @@ void CUDT::construct()
m_bClosing = false;
m_bShutdown = false;
m_bBroken = false;
m_bBreakAsUnstable = false;
// TODO: m_iBrokenCounter should be still set to some default.
m_bPeerHealth = true;
m_RejectReason = SRT_REJ_UNKNOWN;
Expand Down Expand Up @@ -10780,15 +10780,15 @@ bool CUDT::checkExpTimer(const steady_clock::time_point& currtime, int check_rea
next_exp_time = m_tsLastRspTime + exp_timeout;
}

if (currtime <= next_exp_time)
if (currtime <= next_exp_time && !m_bBreakAsUnstable)
return false;

// ms -> us
const int PEER_IDLE_TMO_US = m_config.iPeerIdleTimeout * 1000;
// Haven't received any information from the peer, is it dead?!
// timeout: at least 16 expirations and must be greater than 5 seconds
if ((m_iEXPCount > COMM_RESPONSE_MAX_EXP) &&
(currtime - m_tsLastRspTime > microseconds_from(PEER_IDLE_TMO_US)))
if (m_bBreakAsUnstable || ((m_iEXPCount > COMM_RESPONSE_MAX_EXP) &&
(currtime - m_tsLastRspTime > microseconds_from(PEER_IDLE_TMO_US))))
{
//
// Connection is broken.
Expand All @@ -10805,7 +10805,7 @@ bool CUDT::checkExpTimer(const steady_clock::time_point& currtime, int check_rea
m_pSndQueue->m_pSndUList->update(this, CSndUList::DO_RESCHEDULE);

updateBrokenConnection();
completeBrokenConnectionDependencies(SRT_ECONNLOST); // LOCKS!
completeBrokenConnectionDependencies(m_bBreakAsUnstable ? SRT_ECONNUNSTABLE : SRT_ECONNLOST); // LOCKS!

return true;
}
Expand Down
4 changes: 4 additions & 0 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ class CUDT
SRTU_PROPERTY_RR(srt::sync::Condition*, recvDataCond, &m_RecvDataCond);
SRTU_PROPERTY_RR(srt::sync::Condition*, recvTsbPdCond, &m_RcvTsbPdCond);

/// @brief Request a socket to be broken due to too long instability (normally by a group).
void breakAsUnstable() { m_bBreakAsUnstable = true; }

void ConnectSignal(ETransmissionEvent tev, EventSlot sl);
void DisconnectSignal(ETransmissionEvent tev);

Expand Down Expand Up @@ -726,6 +729,7 @@ class CUDT
volatile bool m_bClosing; // If the UDT entity is closing
volatile bool m_bShutdown; // If the peer side has shutdown the connection
volatile bool m_bBroken; // If the connection has been broken
volatile bool m_bBreakAsUnstable; // A flag indicating that the socket should become broken because it has been unstable for too long.
volatile bool m_bPeerHealth; // If the peer status is normal
volatile int m_RejectReason;
bool m_bOpened; // If the UDT entity has been opened
Expand Down
48 changes: 7 additions & 41 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3091,43 +3091,6 @@ void CUDTGroup::sendBackup_CheckIdleTime(gli_t w_d)
}
}

/// TODO: Remove 'weight' parameter? Only needed for logging.
/// @retval 1 - link is identified as stable
/// @retval 0 - link state remains unchanged (too early to identify, still in activation phase)
/// @retval -1 - link is identified as unstable
static int sendBackup_CheckRunningLinkStable(const CUDT& u, const srt::sync::steady_clock::time_point& currtime, uint16_t weight ATR_UNUSED)
{
const uint32_t latency_us = u.peerLatency_us();
const int32_t min_stability_us = 60000; // Minimum Link Stability Timeout: 60ms.
const int64_t initial_stabtout_us = max<int64_t>(min_stability_us, latency_us);
const int64_t activation_period_us = initial_stabtout_us + 5 * CUDT::COMM_SYN_INTERVAL_US;

// RTT and RTTVar values are still being refined during activation period,
// therefore the dymanic timeout should not be used in activation phase.
const bool is_activation_phase = !is_zero(u.freshActivationStart())
&& (count_microseconds(currtime - u.freshActivationStart()) <= activation_period_us);

const int64_t stability_tout_us = is_activation_phase
? initial_stabtout_us // activation phase
: min<int64_t>(max<int64_t>(min_stability_us, 2 * u.SRTT() + 4 * u.RTTVar()), latency_us);

const steady_clock::time_point last_rsp = max(u.freshActivationStart(), u.lastRspTime());
const steady_clock::duration td_response = currtime - last_rsp;
if (count_microseconds(td_response) > stability_tout_us)
{
#if SRT_DEBUG_BONDING_STATES
s_stab_trace.trace(u, currtime, activation_period_us, stability_tout_us, is_activation_phase ? "ACTIVATION-UNSTABLE" : "UNSTABLE", weight);
#endif
return -1;
}

// u.lastRspTime() > currtime is alwats true due to the very first check above in this function
#if SRT_DEBUG_BONDING_STATES
s_stab_trace.trace(u, currtime, activation_period_us, stability_tout_us, is_activation_phase ? "ACTIVATION" : "STABLE", weight);
#endif
return is_activation_phase ? 0 : 1;
}

// [[using locked(this->m_GroupLock)]]
CUDTGroup::BackupMemberState CUDTGroup::sendBackup_QualifyActiveState(const gli_t d, const time_point currtime)
{
Expand Down Expand Up @@ -3551,12 +3514,15 @@ void CUDTGroup::sendBackup_CheckUnstableSockets(SendBackupCtx& w_sendBackupCtx,
if (unstable_for_ms < sock.peerIdleTimeout_ms())
continue;

// Requesting this socket to be broken with the next CUDT::checkExpTimer() call.
sock.breakAsUnstable();

LOGC(gslog.Warn, log << "grp/send*: Socket @" << member->socketID << " is unstable for " << unstable_for_ms
<< "ms - qualifying as broken.");
<< "ms - requesting breakage.");

w_sendBackupCtx.updateMemberState(member->pSocketData, BKUPST_BROKEN);
if (member->pSocketData->ps)
sendBackup_AssignBackupState(member->pSocketData->ps->core(), BKUPST_BROKEN, currtime);
//w_sendBackupCtx.updateMemberState(member->pSocketData, BKUPST_BROKEN);
//if (member->pSocketData->ps)
// sendBackup_AssignBackupState(member->pSocketData->ps->core(), BKUPST_BROKEN, currtime);
}
}

Expand Down
2 changes: 2 additions & 0 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ enum CodeMinor
// MJ_CONNECTION
MN_CONNLOST = 1,
MN_NOCONN = 2,
MN_UNSTABLE = 3,
// MJ_SYSTEMRES
MN_THREAD = 1,
MN_MEMORY = 2,
Expand Down Expand Up @@ -501,6 +502,7 @@ typedef enum SRT_ERRNO
SRT_ECONNFAIL = MJ(CONNECTION),
SRT_ECONNLOST = MN(CONNECTION, CONNLOST),
SRT_ENOCONN = MN(CONNECTION, NOCONN),
SRT_ECONNUNSTABLE = MN(CONNECTION, UNSTABLE),

SRT_ERESOURCE = MJ(SYSTEMRES),
SRT_ETHREAD = MN(SYSTEMRES, THREAD),
Expand Down
1 change: 1 addition & 0 deletions srtcore/strerror_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const char* strerror_msgs_connection [] = {
"", // MN_NONE = 0
"Connection was broken", // MN_CONNLOST = 1
"Connection does not exist", // MN_NOCONN = 2
"Connection broken as unstable", // MN_UNSTABLE = 3
""
};

Expand Down

0 comments on commit 58ffe25

Please sign in to comment.