Skip to content

Commit d3b151c

Browse files
authored
Merge pull request #2 from invariantlabs-ai/playground
Error handling + cleanup
2 parents 3ad33cf + f93110c commit d3b151c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

server/ipc/controller.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ def _init(self):
2323
self.start_process()
2424

2525
def exists(self):
26+
if not os.path.exists(self.socket_path):
27+
self.close()
28+
return False
29+
2630
if settings.production:
27-
return os.path.exists(self.socket_path)
31+
return True
2832

2933
process = False
3034
for proc in psutil.process_iter():
@@ -92,7 +96,8 @@ def close(self):
9296
break
9397
except (psutil.AccessDenied, psutil.ZombieProcess, psutil.NoSuchProcess):
9498
continue
95-
os.remove(self.socket_path)
99+
if os.path.exists(self.socket_path):
100+
os.remove(self.socket_path)
96101

97102

98103
class IpcControllerSingleton:

server/ipc/invariant-ipc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def worker(client_socket):
4848
data = client_socket.recv(10 * 1024 * 1024)
4949
response = handle_request(data)
5050
client_socket.sendall(response)
51+
except Exception as e:
52+
client_socket.sendall(json.dumps(str(e)).encode())
5153
finally:
5254
client_socket.close()
5355

0 commit comments

Comments
 (0)