-
Notifications
You must be signed in to change notification settings - Fork 865
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
UDP ports, option SRTO_REUSEADDR and srt_close() #1892
Comments
See #1822. As an explanation: The real occupant of the UDP socket is the object called "multiplexer", which can potentially be shared between SRT sockets. It is always shared between a listener socket and sockets accepted off it, as well as it can be shared by another socket when you call Closing a socket is a complicated thing because the socket you want to close might still be in use by other threads, some pending activities and data transmission may be underway, including reading the data in another thread. That's why the original design contained also a Garbage Collector, which made the sockets cleaned up after making sure that all other activities around them are finished. And there is the place where the "disconnection from multiplexer" (and potentially deleting it, when it was the last share) for the socket is happening. There is already an initiative started to fix it, but the fix is a bit complicated, so this will need time. |
Hi @ethouris Thanks for the explanation. It is clear. In practice, I have no problem with the underlying UDP socket still being active. On the contrary, it probably has a lot of advantages. My problem is that calling another
Sharing the same UDP socket between multiple SRT sockets (in sequence, not at the same time) is precisely what I would like to do but it fails with "Another socket is already listening on the same port". |
We have this "issue" also in our SRT solution. Based on our experience we created a while loop and in the loop we are trying to create a socket. It's can take some time until a previous socket is deleted in the kernel. |
So, what would you recommend in order to create an SRT socket on the same port as a previous SRT socket in the same application? Using standard UDP sockets, we know that it may take time for a socket to be deleted but specifying REUSEADDR immediately in the new socket works. What about SRT sockets? |
@lelegard "Rebinding" a socket to the same port should work without problems, as long as you do it in the same application. If you have multiple SRT applications running on one machine then they will be rivalling for the same resources with other applications, also a completely non-SRT application trying to occupy a UDP port by its own UDP socket. "Certainty" that a UDP socket associated with a multiplexer will be closed at some time requires some prerequisites - and, of course, as for now also some patience. For example, if you have a socket that you have sent some packets to, and they haven't been sent yet over the connection (still enqueued), the resources will not be freed until the buffers are empty. If we are able to provide the fix to do "early multiplexer disconnection", then it will disconnect the multiplexer at the earliest possible time, but this doesn't mean that the UDP resources will be freed exactly after calling |
Ah, as for REUSEADDR option (or REUSEPORT) - be careful. There are information that their portability is often questionable, as well as you better make sure that the UDP socket used by SRT is really not in use at the moment. This option may make the system deliver a packet sent to that socket to the (randomly) first application that requested reading. |
@ethouris, this is precisely what I am trying to do, but it does not work ("Operation not supported: Another socket is already listening on the same port"). Have a look at the debug traces in my original post to see the scenario. Did I miss some option? |
That's why I'm asking how exactly you are doing it. This error occurs exclusively in one case: when you have another listener socket bound to this port. There was a problem in early UDT codebase that you couldn't do it as well, but it was fixed in SRT. When you close the previous listening socket, a new listening socket should be able to be bound to the port used by the previous listener. That's not a problem with "binding" because binding multiple sockets to the same address is allowed, just only one of these sockets is allowed to be a listener. |
Yes, exactly. If you have a look at the debug traces, you will see that the SRT socket that was listening on the port is closed ( |
Then I have no idea what happened here - in my tests this works without problems. This part of the code is executed on the listener socket when it is being closed (direct call from
The call to
While your call to
And this
In other words, this error is reported because The The procedure of creating the multiplexer or reusing the old one is in |
Hi @ethouris Thanks for your time. I analyzed the code of the SRT plugin in TSDuck (I never really dived into SRT previously) and I found that there was a bug there. After This is unfortunately the second time in a short period that a problem was reported here while it was in fact an issue in the TSDuck SRT plugin. I apologise for this and will be more cautious with TSDuck code contributions in the future. I close this one. |
That's exactly what I thought has happened :) Tx. |
Hi,
I have a question about UDP ports, option
SRTO_REUSEADDR
andsrt_close()
. I do not know if this is the expected beahviour, I am not an SRT specialist.The scenario I run in is the following (detailed traces with SRT options below):
netstat -anu | grep :5555
)srt_close()
, do not exit application.srt_close()
<== Is this normal?SRTO_REUSEADDR
, bind it to UDP port 5555, fails with "Another socket is already listening on the same port" <== Is this normal?This has been seen on Ubuntu 20.10 with libsrt 1.4.1 and also on Windows 10 with libsrt 1.4.3-rc.0.
I am surprised that the UDP port is still in use after
srt_close()
. Also surprised bysrt_bind()
failing despite optionSRTO_REUSEADDR
(unless of coursesrt_close()
does not close the underlying UDP socket).I have tried with various delays between
srt_close()
and the nextsrt_create_socket()
without success.Debug traces using TSDuck:
To check the UDP port status:
Sender command (which produces the traces):
Receiver command (interrupt it using Ctrl-C to reproduce the issue):
Thanks for you help.
The text was updated successfully, but these errors were encountered: