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"
|
||||
|
||||
|
||||
TIMEOUT = 6.0
|
||||
|
||||
|
||||
def _root_loop(socket: socket_module.socket, allowed_commands):
|
||||
socket.listen(1)
|
||||
|
||||
# XXX
|
||||
socket.settimeout(6.0)
|
||||
socket.settimeout(TIMEOUT)
|
||||
while True:
|
||||
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")
|
||||
|
||||
# We accept a single line per connection for simplicity and safety
|
||||
line = pipe.readline()
|
||||
request = line.strip()
|
||||
answer = _process_request(request, allowed_commands)
|
||||
try:
|
||||
conn.send(answer.encode("utf-8"))
|
||||
except TimeoutError:
|
||||
pass
|
||||
pipe.close()
|
||||
conn.close()
|
||||
|
||||
|
|
Loading…
Reference in a new issue