-
Notifications
You must be signed in to change notification settings - Fork 851
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
Thread safety using WSAOVERLAPPED #2838
Comments
We found this issue during our app testing. When sending 400mbps of data in our program, some exceptions quickly occurred and the stack was damaged. The probability of this problem occurring is related to your actual traffic and the performance of the network subsystem. I am currently using a temporary solution, using TLS WSAEvent and stack WSAOVERLAPPED. WSAOVERLAPPED overlapped;
::SecureZeroMemory(&overlapped, sizeof(overlapped));
class WSAEventRef
{
public:
WSAEventRef()
: e(::WSACreateEvent())
{
}
~WSAEventRef()
{
::WSACloseEvent(e);
e = NULL;
}
void reset()
{
::WSAResetEvent(e);
}
WSAEVENT handle()
{
return e;
}
private:
WSAEVENT e;
};
thread_local WSAEventRef lEvent;
overlapped.hEvent = lEvent.handle();
int res = ::WSASendTo(m_iSocket, (LPWSABUF)packet.m_PacketVector, 2, &size, 0, addr.get(), addrsize, &overlapped, nullptr); |
The Windows build of SRT enables C++11 by default. If disabled, the pthread port is being used. But it is waiting to be deprecated. @mGaosi #if HAVE_CXX11
thread_local WSAEventRef lEvent;
#else
WSAEventRef lEvent;
#endif P.S. Look like |
If we state that Windows can only be built with C++11, then it should suffice to declare |
…#2838). The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. This reverts commit b1c0be2. resolves Haivision#2632 Haivision#2834 Haivision#2838
…#2838). The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. This reverts commit b1c0be2. resolves Haivision#973 Haivision#2632 Haivision#2834 Haivision#2838
…#2838). The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. This reverts commit b1c0be2. resolves Haivision#973 Haivision#2632 Haivision#2834 Haivision#2838
The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. Resolves Haivision#973, Haivision#2632, Haivision#2834, Haivision#2838. Co-authored-by: Jiangjie Gao <gaojiangjie@live.com>
The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. Resolves Haivision#973, Haivision#2632, Haivision#2834, Haivision#2838. Co-authored-by: Jiangjie Gao <gaojiangjie@live.com>
The lpOverlapped parameter must be valid for the duration of the overlapped operation. If multiple I/O operations are simultaneously outstanding, each must reference a separate WSAOVERLAPPED structure. Resolves Haivision#973, Haivision#2632, Haivision#2834, Haivision#2838. Co-authored-by: Jiangjie Gao <gaojiangjie@live.com>
Resolved by #2929. |
PR #2834 has a problem, The srt::CChannel::sendto will be call in CSndQueue(thread1) and CRcvQueue(thread2), and that not thread safety.
Them used same WSAOVERLAPPED, so WSASendTo maybe not completed when WSAWaitForMultipleEvents return.
From https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendto
Originally posted by @mGaosi in #2834 (comment)
The text was updated successfully, but these errors were encountered: