[Asterisk-code-review] utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT (testsuite[20])

Friendly Automation asteriskteam at digium.com
Mon Apr 17 07:32:16 CDT 2023


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/20064 )

Change subject: utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT
......................................................................

utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT

Set SO_REUSEADDR and SO_REUSEPORT for both DGRAM and
STREAM sockets in an effort to reduce port exhaustion.

Change-Id: I913302fe69820ceb7c328fc846cd9af5551c9fdc
---
M lib/python/asterisk/utils_socket.py
1 file changed, 17 insertions(+), 4 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit




diff --git a/lib/python/asterisk/utils_socket.py b/lib/python/asterisk/utils_socket.py
index c8813bd..f52b0a1 100644
--- a/lib/python/asterisk/utils_socket.py
+++ b/lib/python/asterisk/utils_socket.py
@@ -107,16 +107,17 @@
     res = 0
     s = socket(family, socktype)
     try:
-        if socktype == SOCK_STREAM:
-            s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+        s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+        s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
 
         s.bind((host, port))
         res = s.getsockname()[1]
     except error as e:
         # errno = 98 is 'Port already in use'. However, if any error occurs
         # just fail since we probably don't want to bind to it anyway.
-        LOGGER.debug("{0}/{1} port '{2}' is in use".format(
-            socket_type(socktype), socket_family(family), port))
+        LOGGER.debug(e)
+        LOGGER.debug("{3}: {0}/{1} port '{2}' is in use".format(
+            socket_type(socktype), socket_family(family), port, host))
 
     s.close()
     return res

-- 
To view, visit https://gerrit.asterisk.org/c/testsuite/+/20064
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 20
Gerrit-Change-Id: I913302fe69820ceb7c328fc846cd9af5551c9fdc
Gerrit-Change-Number: 20064
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230417/04ef8cc1/attachment.html>


More information about the asterisk-code-review mailing list