Skip to content

Commit

Permalink
[core] Fixed clearing errored group in connecting (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Dec 2, 2020
1 parent c42bc13 commit d340f6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,11 +1344,13 @@ int CUDTUnited::groupConnect(CUDTGroup* pg, SRT_SOCKGROUPCONFIG* targets, int ar
const bool was_empty = g.groupEmpty();

// In case the group was retried connection, clear first all epoll readiness.
m_EPoll.update_events(g.id(), g.m_sPollID, SRT_EPOLL_ERR, false);
if (was_empty)
const int ncleared = m_EPoll.update_events(g.id(), g.m_sPollID, SRT_EPOLL_ERR, false);
if (was_empty || ncleared)
{
HLOGC(aclog.Debug, log << "srt_connect/group: clearing IN/OUT because was_empty=" << was_empty << " || ncleared=" << ncleared);
// IN/OUT only in case when the group is empty, otherwise it would
// clear out correct readiness resulting from earlier calls.
// This also should happen if ERR flag was set, as IN and OUT could be set, too.
m_EPoll.update_events(g.id(), g.m_sPollID, SRT_EPOLL_IN | SRT_EPOLL_OUT, false);
}
SRTSOCKET retval = -1;
Expand Down
4 changes: 3 additions & 1 deletion srtcore/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ int CEPoll::update_events(const SRTSOCKET& uid, std::set<int>& eids, const int e
return -1; // still, ignored.
}

int nupdated = 0;
vector<int> lost;

IF_HEAVY_LOGGING(ostringstream debug);
Expand Down Expand Up @@ -901,6 +902,7 @@ int CEPoll::update_events(const SRTSOCKET& uid, std::set<int>& eids, const int e
// - if enable, it will set event flags, possibly in a new notice object
// - if !enable, it will clear event flags, possibly remove notice if resulted in 0
ed.updateEventNotice(*pwait, uid, events, enable);
++nupdated;

HLOGC(eilog.Debug, log << debug.str() << ": E" << (*i)
<< " TRACKING: " << ed.DisplayEpollWatch());
Expand All @@ -909,7 +911,7 @@ int CEPoll::update_events(const SRTSOCKET& uid, std::set<int>& eids, const int e
for (vector<int>::iterator i = lost.begin(); i != lost.end(); ++ i)
eids.erase(*i);

return 0;
return nupdated;
}

// Debug use only.
Expand Down
5 changes: 3 additions & 2 deletions srtcore/epoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ friend class CRendezvousQueue;

public: // for CUDT to acknowledge IO status

/// Update events available for a UDT socket.
/// Update events available for a UDT socket. At the end this function
/// counts the number of updated EIDs with given events.
/// @param [in] uid UDT socket ID.
/// @param [in] eids EPoll IDs to be set
/// @param [in] events Combination of events to update
/// @param [in] enable true -> enable, otherwise disable
/// @return 0 if success, otherwise an error number
/// @return -1 if invalid events, otherwise the number of changes

int update_events(const SRTSOCKET& uid, std::set<int>& eids, int events, bool enable);

Expand Down
12 changes: 10 additions & 2 deletions testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,15 @@ void SrtCommon::OpenGroupClient()
NULL, NULL,
NULL, NULL) != -1)
{
Verb() << "[C]" << VerbNoEOL;
for (int i = 0; i < len1; ++i)
Verb() << " " << ready_conn[i] << VerbNoEOL;
Verb() << "[E]" << VerbNoEOL;
for (int i = 0; i < len2; ++i)
Verb() << " " << ready_err[i] << VerbNoEOL;

Verb() << "";

// We are waiting for one entity to be ready so it's either
// in one or the other
if (find(ready_err, ready_err+len2, m_sock) != ready_err+len2)
Expand All @@ -1174,8 +1183,7 @@ void SrtCommon::OpenGroupClient()
--transmit_retry_connect;


Verb() << "...all links timeout, retrying in 250ms (" << transmit_retry_connect << ")...";
std::this_thread::sleep_for(std::chrono::milliseconds(250));
Verb() << "...all links timeout, retrying NOW (" << transmit_retry_connect << ")...";
goto Connect_Again;
}

Expand Down

0 comments on commit d340f6d

Please sign in to comment.