After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710078 - rtspserver test: "racy" behavior in get_unused_port function
rtspserver test: "racy" behavior in get_unused_port function
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-rtsp-server
unspecified
Other Linux
: Normal normal
: 1.2.3
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-14 07:01 UTC by Patricia Muscalu
Modified: 2014-02-25 22:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fixed racy behavior in rtspserver tests (4.58 KB, patch)
2013-10-14 07:01 UTC, Patricia Muscalu
needs-work Details | Review
fixed racy behavior in rtspserver tests (4.59 KB, patch)
2013-10-15 07:18 UTC, Patricia Muscalu
needs-work Details | Review
fixed racy behavior in rtspserver tests (4.30 KB, patch)
2013-10-15 09:15 UTC, Patricia Muscalu
committed Details | Review

Description Patricia Muscalu 2013-10-14 07:01:44 UTC
Created attachment 257231 [details] [review]
fixed racy behavior in rtspserver tests

Running simultaneously test instances, will sooner or later lead to failed test results.
Investigate the get_unused_port function. After a successful call to bind, the port information is retrieved and returned (used later as a global variable test_port).
The problem is that, the function returns the port number after the socket has been closed so the uniqueness of the test port is not guaranteed.

The attached patch suggests a solution to this problem.
Comment 1 Sebastian Dröge (slomo) 2013-10-14 17:57:25 UTC
Review of attachment 257231 [details] [review]:

Generally looks fine to me but:

::: gst/rtsp-server/rtsp-server.c
@@ +853,3 @@
+
+        if (g_socket_address_to_native (sockaddr, &native_addr, sizeof native_addr, &addr_error)) {
+          addr_len = sizeof native_addr;

Please add some () for the sizeof :)

@@ +857,3 @@
+
+          if (getsockname (sock, (struct sockaddr *) &native_addr, &addr_len) == 0) {
+            port = ntohs (native_addr.sin_port);

Use g_ntohs() and don't include netinet/in.h
Comment 2 Patricia Muscalu 2013-10-15 07:18:15 UTC
Created attachment 257321 [details] [review]
fixed racy behavior in rtspserver tests
Comment 3 Patricia Muscalu 2013-10-15 07:19:34 UTC
Thank you for the quick review.

struct sockaddr_in is defined in netinet/in.h so the file has to be included here.
Comment 4 Sebastian Dröge (slomo) 2013-10-15 07:21:58 UTC
Review of attachment 257321 [details] [review]:

::: gst/rtsp-server/rtsp-server.c
@@ +856,3 @@
+          sock = g_socket_get_fd (socket);
+
+          if (getsockname (sock, (struct sockaddr *) &native_addr, &addr_len) == 0) {

Oh sorry, also use g_inet_socket_address_get_port() for portability please. The above most likely does not work properly on Windows.
Comment 5 Patricia Muscalu 2013-10-15 09:14:12 UTC
g_inet_socket_address_get_port, the function I was looking for ... thanks.
I've simplified the code now. netinet/in.h is not needed any longer.
Comment 6 Patricia Muscalu 2013-10-15 09:15:16 UTC
Created attachment 257334 [details] [review]
fixed racy behavior in rtspserver tests
Comment 7 Sebastian Dröge (slomo) 2013-10-15 09:31:38 UTC
commit de7be1c9b2fef55ad9bad38dcb508671bb504d98
Author: Patricia Muscalu <patricia@axis.com>
Date:   Mon Oct 14 08:30:33 2013 +0200

    tests: fixed racy behavior in rtspserver tests
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710078