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

[BUG] SRT socket can't be reused (SO_REUSEADDR) #1837

Closed
hhhansen opened this issue Mar 2, 2021 · 3 comments
Closed

[BUG] SRT socket can't be reused (SO_REUSEADDR) #1837

hhhansen opened this issue Mar 2, 2021 · 3 comments
Labels
Type: Bug Indicates an unexpected problem or unintended behavior

Comments

@hhhansen
Copy link

hhhansen commented Mar 2, 2021

We've noticed that a SRT socket can't be used with the same IP address and port after the previous socket was closed. We've enhanced the function void CChannel::createSocket(int family) with the following two lines:
long reuseaddress = 1;
::setsockopt(m_iSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&reuseaddress, sizeof(reuseaddress));
Please can you add these lines to your source code?

@hhhansen hhhansen added the Type: Bug Indicates an unexpected problem or unintended behavior label Mar 2, 2021
@ethouris
Copy link
Collaborator

ethouris commented Mar 3, 2021

Duplicate: #1822

@ethouris
Copy link
Collaborator

ethouris commented Mar 3, 2021

And one more thing: setting SO_REUSEADDR on the UDP socket allocated for the SRT Multiplexer object is a wrong approach. This flag causes that multiple sockets can be assigned to the same address, and therefore when reading from any of these two sockets the application will deliver the packet that was sent to this bound address. There's another fix pending for correct check for the binding process, which checks binding collision before it could fail due to system binding - without this fix the current code relies on that an attempt to bind a UDP socket would fail in case of collision. Such a fix (setting SO_REUSEADDR to 1) prevents this error and allows potentially multiple SRT sockets to be bound to the same address without sharing the multiplexer, which means that packets destined to one of them would be retrieved by a randomly chosen one of these sockets.

@hhhansen
Copy link
Author

I'm not sure if you are right, but nethertheless it's only important for us, how you will fix the issue!
SO_REUSEADDR
Indicates that the rules used in validating addresses
supplied in a bind(2) call should allow reuse of local
addresses. For AF_INET sockets this means that a socket
may bind, except when there is an active listening socket
bound to the address. When the listening socket is bound
to INADDR_ANY with a specific port then it is not possible
to bind to this port for any local address. Argument is
an integer boolean flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants