Fix inter-process communication issues

- Fix SocketCommunicator initialization to properly handle TCP vs Unix sockets
- Update backend to use configurable communication type from config
- Change default communication type from 'unix' to 'tcp' for better reliability
- Ensure consistent socket handling across all processes
parent 2604b812
...@@ -104,12 +104,25 @@ def backend_process() -> None: ...@@ -104,12 +104,25 @@ def backend_process() -> None:
"""Main backend process loop.""" """Main backend process loop."""
print("Starting Video AI Backend...") print("Starting Video AI Backend...")
# Start web server on port 5001 from .config import get_comm_type, get_backend_web_port, get_backend_worker_port
web_server = SocketServer(port=5001) comm_type = get_comm_type()
print(f"Using {comm_type} sockets for communication")
# Start web server
if comm_type == 'unix':
from .compat import get_socket_path
web_socket_path = get_socket_path('web')
web_server = SocketServer(socket_path=web_socket_path, comm_type='unix')
else:
web_server = SocketServer(host='localhost', port=get_backend_web_port(), comm_type='tcp')
web_server.start(handle_web_message) web_server.start(handle_web_message)
# Start worker server on port 5002 # Start worker server
worker_server = SocketServer(port=5002) if comm_type == 'unix':
worker_socket_path = get_socket_path('worker')
worker_server = SocketServer(socket_path=worker_socket_path, comm_type='unix')
else:
worker_server = SocketServer(host='localhost', port=get_backend_worker_port(), comm_type='tcp')
worker_server.start(worker_message_handler) worker_server.start(worker_message_handler)
try: try:
......
...@@ -44,9 +44,12 @@ class SocketCommunicator: ...@@ -44,9 +44,12 @@ class SocketCommunicator:
self.comm_type = comm_type self.comm_type = comm_type
if comm_type == 'unix': if comm_type == 'unix':
self.socket_path = socket_path self.socket_path = socket_path
self.host = None
self.port = None
else: else:
self.host = host self.host = host
self.port = port self.port = port
self.socket_path = None
self.sock: Optional[socket.socket] = None self.sock: Optional[socket.socket] = None
def connect(self) -> None: def connect(self) -> None:
......
...@@ -195,7 +195,7 @@ def set_allowed_dir(dir_path: str) -> None: ...@@ -195,7 +195,7 @@ def set_allowed_dir(dir_path: str) -> None:
def get_comm_type() -> str: def get_comm_type() -> str:
"""Get communication type.""" """Get communication type."""
return get_config('comm_type', 'unix') return get_config('comm_type', 'tcp')
def set_comm_type(comm_type: str) -> None: def set_comm_type(comm_type: str) -> None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment