mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-31 05:06:41 +00:00
feature(root_daemon): robustness with timeout
This commit is contained in:
parent
c40e68000e
commit
f21e59f99f
|
@ -117,20 +117,31 @@ def _process_request(request: str, allowed_commands: str) -> str:
|
||||||
return "not permitted"
|
return "not permitted"
|
||||||
|
|
||||||
|
|
||||||
|
TIMEOUT = 6.0
|
||||||
|
|
||||||
|
|
||||||
def _root_loop(socket: socket_module.socket, allowed_commands):
|
def _root_loop(socket: socket_module.socket, allowed_commands):
|
||||||
socket.listen(1)
|
socket.listen(1)
|
||||||
|
|
||||||
# XXX
|
socket.settimeout(TIMEOUT)
|
||||||
socket.settimeout(6.0)
|
|
||||||
while True:
|
while True:
|
||||||
conn, addr = socket.accept()
|
try:
|
||||||
|
conn, addr = socket.accept()
|
||||||
|
except TimeoutError:
|
||||||
|
continue
|
||||||
|
# conn is a new socket
|
||||||
|
# TODO: check that it can inherit timeout
|
||||||
|
conn.settimeout(TIMEOUT)
|
||||||
pipe = conn.makefile("rw")
|
pipe = conn.makefile("rw")
|
||||||
|
|
||||||
# We accept a single line per connection for simplicity and safety
|
# We accept a single line per connection for simplicity and safety
|
||||||
line = pipe.readline()
|
line = pipe.readline()
|
||||||
request = line.strip()
|
request = line.strip()
|
||||||
answer = _process_request(request, allowed_commands)
|
answer = _process_request(request, allowed_commands)
|
||||||
conn.send(answer.encode("utf-8"))
|
try:
|
||||||
|
conn.send(answer.encode("utf-8"))
|
||||||
|
except TimeoutError:
|
||||||
|
pass
|
||||||
pipe.close()
|
pipe.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue