lpereira / lwan

Experimental, scalable, high performance HTTP server
https://lwan.ws
GNU General Public License v2.0
5.92k stars 549 forks source link

socket activation fails with `Could not parse socket activation data from systemd: Invalid argument (error number 22)` #357

Closed eriksjolund closed 1 year ago

eriksjolund commented 1 year ago

Short summary: There is some parsing bug somewhere in strv_split() or sd_listen_fds_with_names(). It only worked after doing a workaround https://github.com/eriksjolund/lwan/commit/408a6888cf8f8d62ad634d7108018a2e9168ff4e

Reproducer:

On a Fedora CoreOS VM

  1. Create user test
    sudo useradd test
  2. Start a login shell as user test
    sudo machinectl shell test@
  3. Clone the lwan git repository to ~/lwan
  4. Build the image
    podman build -t lwan ~/lwan
  5. Create directories
    mkdir -p ~/.config/containers/systemd
    mkdir -p ~/.config/systemd/user
  6. Create the file ~/lwan.conf with the contents

    listener systemd:my.socket
    
    site {
       serve_files / {
               path = /web
       }
    }
  7. Create the file ~/.config/systemd/user/my.socket with the contents
    [Socket]
    ListenStream=8080
  8. Create the file ~/.config/containers/systemd/my.container with the contents

    [Unit]
    After=my.socket
    Requires=my.socket
    
    [Container]
    Network=none
    Image=localhost/lwan
    Volume=/home/test/lwan.conf:/lwan.conf:Z
    Volume=/home/test/web:/web:Z

    The option :Z is needed on SELinux systems. As lwan only needs to communicate over the socket-activated socket, it's possible to use Network=none

  9. Create the web directory and an example text file
    mkdir ~/web
    echo hello > ~/web/file.txt
  10. Reload systemd configuration
    systemctl --user daemon-reload
  11. Start the socket
    systemctl --user start my.socket
  12. Enable systemd debug logging
    pkill --signal SIGRTMIN+22 -u $USER systemd
  13. Download the example text file from the lwan web server
    curl localhost:8080/file.txt

    The command fails.

  14. Check the logs
    journalctl --user -xeu my.service

    The log contains

    Jul 19 07:17:49 localhost.localdomain systemd-my[22070]: Could not parse socket activation data from systemd: Invalid argument (error number 22)
    Jul 19 07:17:49 localhost.localdomain systemd-my[22070]: Could not create listen_fd
lpereira commented 1 year ago

Thanks for the report! I'll take a look over the weekend.

lpereira commented 1 year ago

This should be fixed. Could you please try the latest HEAD and report back?

On Wed, Jul 19, 2023, at 6:36 AM, Erik Sjölund wrote:

Short summary: There is some parsing bug somewhere in strv_split() or sd_listen_fds_with_names(). It only worked after doing workaround @.***

Reproducer:

On a Fedora CoreOS VM

  1. Create user test sudo useradd test
  2. Start a login shell as user test sudo machinectl shell test@
  3. Clone the lwan git repository to ~/lwan
  4. Build the image podman build -t lwan ~/lwan
  5. Create directories mkdir -p ~/.config/containers/systemd mkdir -p ~/.config/systemd/user
  6. Create the file ~/.config/systemd/user/my.socket with the contents [Socket] ListenStream=8080
  7. Create the file ~/.config/containers/systemd/my.container with the contents `[Unit] After=my.socket Requires=my.socket

[Container] Network=none Image=localhost/lwan Volume=/home/test/lwan.conf:/lwan.conf:Z Volume=/home/test/web:/web:Z The option:Zis needed on SELinux systems. As *lwan* only needs to communicate over the socket-activated socket, it's possible to useNetwork=none`

  1. Create the web directory and an example text file mkdir ~/web echo hello > ~/web/file.txt
  2. Reload systemd configuration systemctl --user daemon-reload
  3. Start the socket systemctl --user start my.socket
  4. Enable systemd debug logging pkill --signal SIGRTMIN+22 -u $USER systemd
  5. Download the example text file from the lwan web server curl localhost:8080/file.txt The command fails.
  6. Check the logs journalctl --user -xeu my.service The log contains Jul 19 07:17:49 localhost.localdomain systemd-my[22070]: Could not parse socket activation data from systemd: Invalid argument (error number 22) Jul 19 07:17:49 localhost.localdomain systemd-my[22070]: Could not create listen_fd

— Reply to this email directly, view it on GitHub https://github.com/lpereira/lwan/issues/357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADVGLBDR7WBGH5HRSNKILXQ557JANCNFSM6AAAAAA2PNZAIQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

eriksjolund commented 1 year ago

Thanks, I tried the latest HEAD and it now works!