Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/services/joern_server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from docker.errors import DockerException, NotFound, APIError

from .port_manager import PortManager
from ..config import load_config

logger = logging.getLogger(__name__)

config = load_config("config.yaml")

class JoernServerManager:
"""Manages individual Joern server instances running in Docker container using Docker Python API"""
Expand Down Expand Up @@ -97,7 +98,7 @@ def spawn_server(self, codebase_hash: str) -> int:
self._exec_ids[codebase_hash] = f"exec-{codebase_hash}"
self._ports[codebase_hash] = port

logger.info(f"Joern server command executed, waiting for server to be ready on port {port}...")
logger.info(f"Joern server command executed, waiting for server to be ready at {config.joern.server_host}:{port}...")

# Wait for server to start (JVM + Scala REPL init can take >60s in Docker)
startup_timeout = self.config.joern.server_startup_timeout if self.config else 120
Expand Down Expand Up @@ -168,7 +169,7 @@ def get_or_create_client(self, codebase_hash: str) -> 'JoernServerClient':
}

client = JoernServerClient(
host="localhost",
host=config.joern.server_host,
port=port,
username=self.config.joern.server_auth_username if self.config else None,
password=self.config.joern.server_auth_password if self.config else None,
Expand Down Expand Up @@ -275,7 +276,7 @@ def is_server_running(self, codebase_hash: str) -> bool:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(('localhost', port))
result = sock.connect_ex((config.joern.server_host, port))
sock.close()
return result == 0
except Exception as e:
Expand Down Expand Up @@ -347,14 +348,14 @@ def _wait_for_server(self, port: int, timeout: int = 30) -> bool:
# Try to connect to the port
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(('localhost', port))
result = sock.connect_ex((config.joern.server_host, port))
sock.close()

if result == 0:
# Server port is open, now check HTTP
try:
import requests
response = requests.get(f"http://localhost:{port}", timeout=2)
response = requests.get(f"http://{config.joern.server_host}:{port}", timeout=2)
# Server responds (even 404 is OK - means it's up)
if response.status_code in [200, 404]:
server_responding = True
Expand Down Expand Up @@ -390,4 +391,4 @@ def _cleanup_server(self, codebase_hash: str) -> None:
logger.debug(f"Closed HTTP session for {codebase_hash}")
except Exception as e:
logger.warning(f"Error closing HTTP session for {codebase_hash}: {e}")
del self._clients[codebase_hash]
del self._clients[codebase_hash]