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

Unable to use socket file for HTTP with --init-db nor db migrate #790

Open
chennin opened this issue Oct 10, 2023 · 1 comment
Open

Unable to use socket file for HTTP with --init-db nor db migrate #790

chennin opened this issue Oct 10, 2023 · 1 comment
Labels

Comments

@chennin
Copy link

chennin commented Oct 10, 2023

Describe the bug

v0.14.0 added the ability to listen on a Unix socket, but it is not possible to reproducibly/cleanly use it (i.e. in a docker container) because --init-db and db migrate fail because they both call shutdown() which tries to remove the socket file that was never set up.

defer shutdown(apper.App())

defer shutdown(apper.App())

Other locations may also do this (ResetPassword?).

Steps to reproduce (if necessary)

Start from a clean directory/image - example: docker run -it --rm ubuntu:22.04

Run the following to reliably reproduce:

apt-get update && apt-get install -y wget && cd /tmp && \
wget https://github.com/writefreely/writefreely/releases/download/v0.15.0/writefreely_0.15.0_linux_amd64.tar.gz && \
tar xvf writefreely_*amd64.tar.gz && cd writefreely && \
./writefreely --create-config && ./writefreely keys generate && \
sed -i -e 's@^bind .*@bind = /tmp/writef.sock@' \
       -e 's@^type .*@type = sqlite3@' \
       -e 's@^filename .*@filename = writefreely.db@' \
    config.ini && \
./writefreely --init-db && \
./writefreely

The important part being: create a config that uses a socket file, then try to initialize the database.

Alternate repro: take an existing working setup that uses a socket, and try to run writefreely db migrate.

The logs in the migrate case are shorter and look like this:

root@683625a2975b:/tmp/writefreely# ./writefreely db migrate
2023/10/10 14:09:48 Loading config.ini configuration...
2023/10/10 14:09:48 Connecting to sqlite3 database...
2023/10/10 14:09:48 Database up-to-date. No migrations to run.
2023/10/10 14:09:48 Closing database connection...
2023/10/10 14:09:48 Removing socket file...
ERROR: 2023/10/10 14:09:48 app.go:865: Unable to remove socket: remove /tmp/writef.sock: no such file or directory
root@683625a2975b:/tmp/writefreely# echo $?
1

Expected behavior

writefreely starts up using a socket for HTTP connections. db migrations/inits don't fail on a missing HTTP socket file.

Application configuration

  • Single mode or Multi-user mode? single
  • Database? sqlite
  • Open registration? default
  • Federation enabled? default

Version or last commit:

0.14.0

cc: @clarfonthey

@chennin
Copy link
Author

chennin commented Feb 4, 2024

Updated repro for 0.15.0.

This causes upgrades (db migrations) to print an error and os.Exit(1) on installations that are using a socket, even if the migration is successful. Expected behavior is to not exit with a failure code on non-failures.

Should being unable to delete the socket file be a fatal error? Or can paths that don't set up the listener, and aren't supposed to set up the listener, be changed to not try to remove it?

root@f8dcc12ce2f8:/tmp/writefreely# ./writefreely db migrate
2024/02/04 14:59:49 Loading config.ini configuration...
2024/02/04 14:59:49 Connecting to sqlite3 database...
2024/02/04 14:59:49 Migrating to V13: support newsletters
2024/02/04 14:59:49 Migrating to V14: support password resetting
2024/02/04 14:59:49 Migrating to V15: speed up blog post retrieval
2024/02/04 14:59:49 Closing database connection...
2024/02/04 14:59:49 Removing socket file...
ERROR: 2024/02/04 14:59:49 app.go:876: Unable to remove socket: remove /tmp/writef.sock: no such file or directory
root@f8dcc12ce2f8:/tmp/writefreely# echo $?
1

@thebaer thebaer added the bug label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants