Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Display descriptive error message when socket path too long #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
29 changes: 28 additions & 1 deletion gravity/process_manager/supervisor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import errno
import os
import shutil
import socket
import subprocess
import sys
import time
Expand Down Expand Up @@ -194,6 +195,8 @@ def __init__(self, state_dir=None, start_daemon=True, foreground=False):
self.__supervisord_popen = None
self.foreground = foreground

self._check_path_length()

if not exists(self.supervisord_conf_dir):
os.makedirs(self.supervisord_conf_dir)

Expand Down Expand Up @@ -225,7 +228,8 @@ def __supervisord(self):
if not self.__supervisord_is_running():
# any time that supervisord is not running, let's rewrite supervisord.conf
open(self.supervisord_conf_path, "w").write(SUPERVISORD_CONF_TEMPLATE.format(**format_vars))
self.__supervisord_popen = subprocess.Popen(supervisord_cmd, env=os.environ)
self.__supervisord_popen = subprocess.Popen(supervisord_cmd, env=os.environ, stderr=subprocess.PIPE)
nsoranzo marked this conversation as resolved.
Show resolved Hide resolved

rc = self.__supervisord_popen.poll()
if rc:
error("supervisord exited with code %d" % rc)
Expand All @@ -243,6 +247,29 @@ def __get_supervisor(self):
options.realize(args=["-c", self.supervisord_conf_path])
return supervisorctl.Controller(options).get_supervisor()

def _check_path_length(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
bind_path = self.supervisord_conf_path
jdavcs marked this conversation as resolved.
Show resolved Hide resolved
try:
sock.bind(bind_path)
except OSError as e:
if "AF_UNIX path too long" in str(e):
self._handle_socket_path_error()
finally:
sock.close()
os.unlink(bind_path)

def _handle_socket_path_error(self):
msg = f"""
The path to your gravity state directory is too long: "{self.supervisord_conf_dir}".
This path becomes part of a socket address. However, in Unix systems there is a limit to the
length of a socket file path (usually 103-108 bytes). You can choose another path with the
--state-dir option to the Gravity command, or by setting $GRAVITY_STATE_DIR in your
environment:
`galaxy --state-dir /home/shorter-path` or `$GRAVITY_STATE_DIR=/home/shorter-path ./run.sh`
"""
error(msg)

def terminate(self):
if self.foreground:
# if running in foreground, if terminate is called, then supervisord should've already received a SIGINT
Expand Down