##// END OF EJS Templates
hooks: reserver only high-ports to limit possibility of hitting port from rhodecode stack
super-admin -
r4860:d80ce1a5 default
parent child Browse files
Show More
@@ -25,6 +25,7 b' import tempfile'
25 import traceback
25 import traceback
26 import threading
26 import threading
27 import socket
27 import socket
28 import random
28
29
29 from BaseHTTPServer import BaseHTTPRequestHandler
30 from BaseHTTPServer import BaseHTTPRequestHandler
30 from SocketServer import TCPServer
31 from SocketServer import TCPServer
@@ -156,13 +157,19 b' class HttpHooksCallbackDaemon(ThreadedHo'
156 def get_hostname(self):
157 def get_hostname(self):
157 return socket.gethostname() or '127.0.0.1'
158 return socket.gethostname() or '127.0.0.1'
158
159
159 def get_available_port(self):
160 def get_available_port(self, min_port=20000, max_port=65535):
160 mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
161 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
161 mysocket.bind((self.get_hostname(), 0))
162 hostname = self.get_hostname()
162 port = mysocket.getsockname()[1]
163
163 mysocket.close()
164 for _ in range(min_port, max_port):
164 del mysocket
165 pick_port = random.randint(min_port, max_port)
165 return port
166 try:
167 sock.bind((hostname, pick_port))
168 sock.close()
169 del sock
170 return pick_port
171 except OSError:
172 pass
166
173
167 def _prepare(self, txn_id=None, host=None, port=None):
174 def _prepare(self, txn_id=None, host=None, port=None):
168 if not host or host == "*":
175 if not host or host == "*":
General Comments 0
You need to be logged in to leave comments. Login now