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 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
30 changes: 30 additions & 0 deletions 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 @@ -197,6 +198,8 @@ def __init__(self, state_dir=None, start_daemon=True, foreground=False):
if not exists(self.supervisord_conf_dir):
os.makedirs(self.supervisord_conf_dir)

self._check_path_length()

if start_daemon:
self.__supervisord()

Expand Down Expand Up @@ -226,6 +229,7 @@ def __supervisord(self):
# 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)

rc = self.__supervisord_popen.poll()
if rc:
error("supervisord exited with code %d" % rc)
Expand All @@ -243,6 +247,32 @@ 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_sock_path
try:
os.unlink(bind_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this method is called any time the class is instantiated, so supervisord may be running and that would make this unsafe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right - this is a no-go.

sock.bind(bind_path)
except OSError as e:
if "AF_UNIX path too long" in str(e):
self._handle_socket_path_error()
else:
raise e
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