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

Fixing path handling by normalizing paths in 'options.py' #1652

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alexeinazarov
Copy link

@alexeinazarov alexeinazarov commented Jul 19, 2024

This change addresses an issue where paths specified for various settings in the Supervisor configuration file were concatenated incorrectly, resulting in errors such as "couldn't chdir to /path/to/project/path/to/project/build: ENOENT."

The problem stemmed from inconsistent handling of relative paths within the options.py file. The changes involve ensuring the existing normalize_path function is applied to critical areas such as self.here in the process_config_file method, self.logfile, self.pidfile, and server URLs in the realize method. By ensuring all paths are converted to absolute, normalized paths, Supervisor can correctly resolve and manage the paths specified in the configuration file.

These changes improve path handling robustness and prevent path-related errors during process management.

Update:

I identified this bug while testing my C++ application that contains both server and client components. The issue with path handling prompted me to bring it to light. I made the necessary adjustments to ensure the paths are forming correctly. However, handling compatibility issues across different Python versions may take more time, so the fixes are not yet fully integrated into Supervisor.

This is my first pull request, and I am eager to contribute to the project. I understand there are failing tests, and I am committed to resolving these issues with your guidance. I hope this contribution will not only fix the issue but also motivate the community to participate in improving this aspect of Supervisor.

Any guidance or feedback you can provide would be greatly appreciated. Thank you for your understanding and support.

Best regards,
A.

@mnaberez
Copy link
Member

This change addresses an issue where paths specified for various settings in the Supervisor configuration file were concatenated incorrectly

Please provide instructions for how to duplicate the issue:

  • An example supervisord.conf file
  • Your expected result
  • The actual result

@alexeinazarov
Copy link
Author

Dear Administrator,

Thank you for your inquiry regarding pull request #1652, which addresses the issue of incorrectly concatenated paths in the Supervisor configuration file. I appreciate the opportunity to provide further clarification on how to reproduce the issue and the rationale behind the proposed changes.

Instructions to Duplicate the Issue:

Example supervisord.conf File

Here is an example of the supervisord.conf file using relative paths:

; supervisord_relative.conf
[supervisord]
nodaemon=true
minfds=1024
minprocs=200
user=alexey  ; replace 'alexey' with the actual username

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0700
chown=alexey:alexey  ; replace 'alexey' with the actual username

[program:kms_server]
command=./build/kms_server
directory=./build
autostart=true
autorestart=true
stdout_logfile=../logs/kms_server.out.log
stderr_logfile=../logs/kms_server.err.log
startsecs=17
startretries=7

[program:kms_client]
command=./test_kms.sh
directory=.
autostart=true
autorestart=false
stdout_logfile=./logs/kms_client.out.log
stderr_logfile=./logs/kms_client.err.log
startsecs=23
startretries=11

Expected Result

When converting the relative paths to absolute paths, the configuration should be as follows:

; supervisord.conf
[supervisord]
nodaemon=true
minfds=1024
minprocs=200
user=alexey  ; replace 'alexey' with the actual username

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0700
chown=alexey:alexey  ; replace 'alexey' with the actual username

[program:kms_server]
command=/home/alexey/Documents/mit/appsave2/project/build/kms_server
directory=/home/alexey/Documents/mit/appsave2/project/build
autostart=true
autorestart=true
stdout_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_server.out.log
stderr_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_server.err.log
startsecs=17
startretries=7

[program:kms_client]
command=/home/alexey/Documents/mit/appsave2/project/test_kms.sh
directory=/home/alexey/Documents/mit/appsave2/project
autostart=true
autorestart=false
stdout_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_client.out.log
stderr_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_client.err.log
startsecs=23
startretries=11

Actual Result

Due to the path concatenation issue, the resulting configuration file incorrectly concatenates paths, causing errors such as the following highlighted in the directory field of the kms_server program:

; supervisord.conf
[supervisord]
nodaemon=true
minfds=1024
minprocs=200
user=alexey  ; replace 'alexey' with the actual username

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0700
chown=alexey:alexey  ; replace 'alexey' with the actual username

[program:kms_server]
command=/home/alexey/Documents/mit/appsave2/project/build/kms_server
directory=/home/alexey/Documents/mit/appsave2/projecthome/alexey/Documents/mit/appsave2/project/build
autostart=true
autorestart=true
stdout_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_server.out.log
stderr_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_server.err.log
startsecs=17
startretries=7

[program:kms_client]
command=/home/alexey/Documents/mit/appsave2/project/test_kms.sh
directory=/home/alexey/Documents/mit/appsave2/project
autostart=true
autorestart=false
stdout_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_client.out.log
stderr_logfile=/home/alexey/Documents/mit/appsave2/project/logs/kms_client.err.log
startsecs=23
startretries=11

The doubled path in the directory field (directory=/home/alexey/Documents/mit/appsave2/projecthome/alexey/Documents/mit/appsave2/project/build) allowed me to identify the class ServerOptions() in the options.py file that needed to be updated. I reviewed all relevant methods and modified those necessary to use the normalize_path function.

Steps to Reproduce the Issue

  1. Create a project directory and logs directory:

    mkdir -p /home/alexey/Documents/mit/appsave2/project/build
    mkdir -p /home/alexey/Documents/mit/appsave2/project/logs
  2. Place the relative Supervisor configuration file (supervisord_relative.conf) in the project directory.

  3. Run the following script to convert the relative paths to absolute paths:

    #!/bin/bash
    
    set -euo pipefail
    
    project_dir="/home/alexey/Documents/mit/appsave2/project"
    log_dir="$project_dir/logs"
    
    mkdir -p "$project_dir/build" "$log_dir"
    touch "$project_dir/supervisord_relative.conf"
    
    cat <<EOL > "$project_dir/supervisord_relative.conf"
    ; supervisord_relative.conf
    [supervisord]
    nodaemon=true
    minfds=1024
    minprocs=200
    user=alexey
    
    [unix_http_server]
    file=/tmp/supervisor.sock
    chmod=0700
    chown=alexey:alexey
    
    [program:kms_server]
    command=./build/kms_server
    directory=./build
    autostart=true
    autorestart=true
    stdout_logfile=../logs/kms_server.out.log
    stderr_logfile=../logs/kms_server.err.log
    startsecs=17
    startretries=7
    
    [program:kms_client]
    command=./test_kms.sh
    directory=.
    autostart=true
    autorestart=false
    stdout_logfile=./logs/kms_client.out.log
    stderr_logfile=./logs/kms_client.err.log
    startsecs=23
    startretries=11
    EOL
    
    sed -e "s#command=./build/kms_server#command=$project_dir/build/kms_server#g" \
        -e "s#directory=./build#directory=$project_dir/build#g" \
        -e "s#stdout_logfile=../logs/kms_server.out.log#stdout_logfile=$log_dir/kms_server.out.log#g" \
        -e "s#stderr_logfile=../logs/kms_server.err.log#stderr_logfile=$log_dir/kms_server.err.log#g" \
        -e "s#command=./test_kms.sh#command=$project_dir/test_kms.sh#g" \
        -e "s#directory=.#directory=$project_dir#g" \
        -e "s#stdout_logfile=./logs/kms_client.out.log#stdout_logfile=$log_dir/kms_client.out.log#g" \
        -e "s#stderr_logfile=./logs/kms_client.err.log#stderr_logfile=$log_dir/kms_client.err.log#g" \
        "$project_dir/supervisord_relative.conf" > "$project_dir/supervisord.conf"
    
    cat "$project_dir/supervisord.conf"

Conclusion

The script demonstrates the path concatenation issue by producing a configuration file with incorrectly concatenated paths. This issue is due to the inconsistent handling of relative paths within the options.py file of the Supervisor library. The proposed changes in the pull request ensure that all paths are converted to absolute, normalized paths, thereby preventing such errors and improving path handling robustness.

Thank you for considering this detailed explanation. I look forward to any further guidance or feedback to resolve this issue effectively.

Best regards,
A.

Copy link
Member

@mnaberez mnaberez left a comment

Choose a reason for hiding this comment

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

Please remove the hundreds of lines of unrelated style changes so it's possible to see the code changes in the diff.

@@ -55,19 +76,25 @@
from supervisor import xmlrpc
from supervisor import poller


Copy link
Member

Choose a reason for hiding this comment

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

Please remove this and all other unrelated style changes.

@@ -1,3 +1,24 @@
# Changes made by user 'alexeinazarov' to ensure proper path normalization and other improvements:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove these comments listing the changes. The diff will show the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants