GNOME Bugzilla – Bug 710078
rtspserver test: "racy" behavior in get_unused_port function
Last modified: 2014-02-25 22:29:01 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.
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
Created attachment 257321 [details] [review] fixed racy behavior in rtspserver tests
Thank you for the quick review. struct sockaddr_in is defined in netinet/in.h so the file has to be included here.
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.
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.
Created attachment 257334 [details] [review] fixed racy behavior in rtspserver tests
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