Browse Source

fix workers

1.4
clowwindy 11 years ago
parent
commit
ea451344ff
  1. 1
      .travis.yml
  2. 6
      shadowsocks/server.py
  3. 9
      shadowsocks/udprelay.py
  4. 2
      test/workers.json

1
.travis.yml

@ -11,3 +11,4 @@ script:
- python test.py -c test/aes.json - python test.py -c test/aes.json
- python test.py -c test/salsa20.json - python test.py -c test/salsa20.json
- python test.py -c test/server-multi-passwd.json - python test.py -c test/server-multi-passwd.json
- python test.py -c test/workers.json

6
shadowsocks/server.py

@ -299,7 +299,13 @@ def main():
sys.exit() sys.exit()
import signal import signal
signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGTERM, handler)
# master # master
for tcp_server in tcp_servers:
tcp_server.server_close()
for udp_server in udp_servers:
udp_server.close()
for child in children: for child in children:
os.waitpid(child, 0) os.waitpid(child, 0)
else: else:

9
shadowsocks/udprelay.py

@ -137,6 +137,7 @@ class UDPRelay(object):
self._cache = lru_cache.LRUCache(timeout=timeout, self._cache = lru_cache.LRUCache(timeout=timeout,
close_callback=self._close_client) close_callback=self._close_client)
self._client_fd_to_server_addr = lru_cache.LRUCache(timeout=timeout) self._client_fd_to_server_addr = lru_cache.LRUCache(timeout=timeout)
self._closed = False
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0, addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0,
socket.SOCK_DGRAM, socket.SOL_UDP) socket.SOCK_DGRAM, socket.SOL_UDP)
@ -251,7 +252,7 @@ class UDPRelay(object):
self._eventloop = eventloop.EventLoop() self._eventloop = eventloop.EventLoop()
self._eventloop.add(server_socket, eventloop.POLL_IN) self._eventloop.add(server_socket, eventloop.POLL_IN)
last_time = time.time() last_time = time.time()
while True: while not self._closed:
try: try:
events = self._eventloop.poll(10) events = self._eventloop.poll(10)
except (OSError, IOError) as e: except (OSError, IOError) as e:
@ -274,11 +275,17 @@ class UDPRelay(object):
last_time = now last_time = now
def start(self): def start(self):
if self._closed:
raise Exception('closed')
t = threading.Thread(target=self._run) t = threading.Thread(target=self._run)
t.setName('UDPThread') t.setName('UDPThread')
t.setDaemon(False) t.setDaemon(False)
t.start() t.start()
self._thread = t self._thread = t
def close(self):
self._closed = True
self._server_socket.close()
def thread(self): def thread(self):
return self._thread return self._thread

2
test/workers.json

@ -6,5 +6,5 @@
"timeout":300, "timeout":300,
"method":"aes-256-cfb", "method":"aes-256-cfb",
"local_address":"127.0.0.1", "local_address":"127.0.0.1",
"workers": 2 "workers": 4
} }

Loading…
Cancel
Save