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

Connection refused after upgrade #4919

Closed
2 tasks done
MapManagement opened this issue Mar 29, 2024 · 10 comments
Closed
2 tasks done

Connection refused after upgrade #4919

MapManagement opened this issue Mar 29, 2024 · 10 comments

Comments

@MapManagement
Copy link

MapManagement commented Mar 29, 2024

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

After upgrading my docker-compose stack (database and bookstack) container, bookstack isn't able to connect to the MariaDB instance anymore. However, I can ping the database host from the bookstack container and I'm also able to connect to the database via mariadb cli tool.

It seems like that my DB_DATABASE environment variable is stored in some file of the PHP app because of the first startup. I forgot to change the variable from "bookstack" to "bookstackapp" and now PHP tries to connect to the "bookstack" database. Even after changing it back in my environment file, it still tries to connect to "bookstack".

Is there anything I can do about it without completeley redeploying my database container?
I also added one of the log files I retrieved some errors from.

Exact BookStack Version

v24.02.2

Log Content

# /config/log/bookstack/laravel.log
Next Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user 'bookstack'@'%' to database 'bookstack' (SQL: select * from `users` where `system_name` = public limit 1) in /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
Stack trace:
#0 /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(720): Illuminate\Database\Connection->runQueryCallback()
#1 /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(405): Illuminate\Database\Connection->run()
#2 /app/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2705): Illuminate\Database\Connection->select()
#3 /app/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2694): Illuminate\Database\Query\Builder->runSelect()
#4 /app/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3230): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /app/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2693): Illuminate\Database\Query\Builder->onceWithColumns()
#6 /app/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(710): Illuminate\Database\Query\Builder->get()
#7 /app/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(694): Illuminate\Database\Eloquent\Builder->getModels()
#8 /app/www/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(296): Illuminate\Database\Eloquent\Builder->get()
#9 /app/www/app/App/Providers/AuthServiceProvider.php(73): Illuminate\Database\Eloquent\Builder->first()
#10 /app/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(885): BookStack\App\Providers\AuthServiceProvider->BookStack\App\Providers\{closure}()
#11 /app/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(770): Illuminate\Container\Container->build()
#12 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(856): Illuminate\Container\Container->resolve()
#13 /app/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(706): Illuminate\Foundation\Application->resolve()
#14 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->make()
#15 /app/www/app/Users/Models/User.php(98): Illuminate\Foundation\Application->make()
#16 /app/www/app/App/helpers.php(38): BookStack\Users\Models\User::getGuest()
#17 /app/www/app/Settings/SettingService.php(62): user()
#18 /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php(4): BookStack\Settings\SettingService->getForCurrentUser()
#19 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...')
#20 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#21 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire()
#22 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Illuminate\View\Engines\PhpEngine->evaluatePath()
#23 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(195): Illuminate\View\Engines\CompilerEngine->get()
#24 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(178): Illuminate\View\View->getContents()
#25 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\View\View->renderContents()
#26 /app/www/storage/framework/views/6212e6f16538942c654408b0bb64b92abc2fa8d6.php(16): Illuminate\View\View->render()
#27 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...')
#28 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#29 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire()
#30 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Illuminate\View\Engines\PhpEngine->evaluatePath()
#31 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(195): Illuminate\View\Engines\CompilerEngine->get()
#32 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(178): Illuminate\View\View->getContents()
#33 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\View\View->renderContents()
#34 /app/www/vendor/laravel/framework/src/Illuminate/Http/Response.php(69): Illuminate\View\View->render()
#35 /app/www/vendor/laravel/framework/src/Illuminate/Http/Response.php(35): Illuminate\Http\Response->setContent()
#36 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(57): Illuminate\Http\Response->__construct()
#37 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(87): Illuminate\Routing\ResponseFactory->make()
#38 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(626): Illuminate\Routing\ResponseFactory->view()
#39 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(554): Illuminate\Foundation\Exceptions\Handler->renderHttpException()
#40 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(460): Illuminate\Foundation\Exceptions\Handler->prepareResponse()
#41 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(377): Illuminate\Foundation\Exceptions\Handler->renderExceptionResponse()
#42 /app/www/app/Exceptions/Handler.php(89): Illuminate\Foundation\Exceptions\Handler->render()
#43 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(233): BookStack\Exceptions\Handler->render()
#44 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(210): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse()
#45 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException()
#46 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#47 {main}

Hosting Environment

Docker compose template of LinuxServer.io on a Debian Bookworm host

@ssddanbrown
Copy link
Member

Hi @MapManagement,

I forgot to change the variable from "bookstack" to "bookstackapp" and now PHP tries to connect to the "bookstack" database. Even after changing it back in my environment file, it still tries to connect to "bookstack".

First of all, be sure to re-up the stack after changing env vars since restarting containers alone won't allow the changes to take affect, the containers need to be re-created.

Second, Some of the database details can be "sticky" as they are transferred to BookStack's env file on first run when in that kind of setup. Open the www/.env, within the folder/volume location you have mounted as /config for the BookStack container, then update any DB options that don't reflect the current values.

@MapManagement
Copy link
Author

MapManagement commented Mar 30, 2024

Hi @ssddanbrown,
first of all I want to thank you for the fast reply. I checked www/.env and recognized that some options weren't set correctly and therefore changed them to my new values.
I always recreate the whole stack after changing anything concerning the environment variables or the configuration in general. However, I'm facing another problem now.

Eventhough I'm still able to access the database manually within the bookstack container, it tells me that the connection has been refused:
/config/log/bookstack/laravel.log

Next Illuminate\\View\\ViewException: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `system_name` = public limit 1) (View: /app/www/resources/views/layouts/base.blade.php) (View: /app/www/resources/views/layouts/base.blade.php) in /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
Stack trace:
#0 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(60): Illuminate\\View\\Engines\\CompilerEngine->handleViewException()
#1 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Illuminate\\View\\Engines\\PhpEngine->evaluatePath()
#2 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(195): Illuminate\\View\\Engines\\CompilerEngine->get()
#3 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(178): Illuminate\\View\\View->getContents()
#4 /app/www/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\\View\\View->renderContents()
#5 /app/www/vendor/laravel/framework/src/Illuminate/Http/Response.php(69): Illuminate\\View\\View->render()
#6 /app/www/vendor/laravel/framework/src/Illuminate/Http/Response.php(35): Illuminate\\Http\\Response->setContent()
#7 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(57): Illuminate\\Http\\Response->__construct()
#8 /app/www/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(87): Illuminate\\Routing\\ResponseFactory->make()
#9 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(626): Illuminate\\Routing\\ResponseFactory->view()
#10 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(554): Illuminate\\Foundation\\Exceptions\\Handler->renderHttpException()
#11 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(460): Illuminate\\Foundation\\Exceptions\\Handler->prepareResponse()
#12 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(377): Illuminate\\Foundation\\Exceptions\\Handler->renderExceptionResponse()
#13 /app/www/app/Exceptions/Handler.php(89): Illuminate\\Foundation\\Exceptions\\Handler->render()
#14 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(233): BookStack\\Exceptions\\Handler->render()
#15 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(210): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->renderHttpResponse()
#16 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleException()
#17 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#18 {main}
  thrown at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)
[stacktrace]
#0 {main}
"}

@ssddanbrown
Copy link
Member

Does the database password container any special characters?

@MapManagement
Copy link
Author

MapManagement commented Apr 1, 2024

Just letters and numbers. I have also changed it several times to make sure, that there's no problem with length or characters, but BookStack still cannot connect to the DB container.

@ssddanbrown
Copy link
Member

Can you access bash in the running BookStack container, then run the following:

cd /app/www
php artisan tinker --execute="dd(config('database.connections.mysql'));"
  • Do the show details reflect those that you expect?
  • If so, does connecting via mysql on the command line within the BookStack container, using all the exact same details, work okay?
    • Run a select * from userswheresystem_name = public limit 1 query just to be sure that table access is as expected.
  • Are you also getting errors in the BookStack container logs when it starts up?

@MapManagement
Copy link
Author

First of all, i would like to thank you very much for your help.

Do the show details reflect those that you expect?

All details are correct and are also in use when I try connecting manually.

If so, does connecting via mysql on the command line within the BookStack container, using all the exact same details, work okay?

The given select runs perfectly fine and is not blocked or not permitted.

Are you also getting errors in the BookStack container logs when it starts up?

Yes, the same error I found in the log file:

   Illuminate\Database\QueryException

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = bookstackapp and table_name = migrations and table_type = 'BASE TABLE')

  at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

      +39 vendor frames
  40  /app/www/artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

@ssddanbrown
Copy link
Member

Very strange then, not sure what's going on.
Can you share the full output of the previously shared bash command? and the full manual mysql command used? Just to understand the options and potential networking in play (Of course, obsficate password and mention any other changes made to hide sensitive info)

@MapManagement
Copy link
Author

Output of bash command (only changed the password):

PHP Warning:  PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
array:15 [ // vendor/psy/psysh/src/ExecutionClosure.php(40) : eval()'d code:1
  "driver" => "mysql"
  "url" => null
  "host" => "bookstack_db"
  "database" => "bookstackapp"
  "username" => "bookstack"
  "password" => "my_database_user_password"
  "unix_socket" => ""
  "port" => "3006"
  "charset" => "utf8mb4"
  "collation" => "utf8mb4_unicode_ci"
  "prefix" => ""
  "prefix_indexes" => true
  "strict" => false
  "engine" => null
  "options" => []
]

And the manual MySQL command:

# connecting from bookstack container (entering password when asked for)
mariadb -u bookstack -p -h bookstack_db

# set database operating on
MariaDB [(none)]> use bookstackapp;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

# executing select
MariaDB [bookstackapp]> select * from users where system_name = 'public' limit 1;
# ...
1 row in set (0.004 sec)

@ssddanbrown
Copy link
Member

Hi @MapManagement,
Thanks for the detail. I see one significant difference between those connections, the port.
BookStack is using 3006 whereas I'm the command line has no port defined so I assume it's falling back to the default 3306 port number.

Do you have a DB_PORT value defined as part of your docker compose setup for the BookStack container? If so is the current value 3006? If so, try changing that to 3306.

@MapManagement
Copy link
Author

I couldn't see the forest for the trees. It actually was the port definition in my env file. Thank your very much! :)

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

No branches or pull requests

2 participants