[GH-ISSUE #1085] Can't connect to DB: BadConnection #768

Closed
opened 2026-03-03 02:03:00 +03:00 by kerem · 10 comments
Owner

Originally created by @okami-chen on GitHub (Aug 5, 2020).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/1085

Subject of the issue

Your environment

  • Bitwarden_rs version:
  • Install method:
  • Clients used:
  • Reverse proxy and version:
  • Version of mysql/postgresql:
  • Other relevant information:

Steps to reproduce

Expected behaviour

Actual behaviour

Relevant logs

[2020-08-05 14:20:17.397][panic][ERROR] thread 'main' panicked at 'Can't connect to DB: BadConnection("Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (2)")': src/main.rs:235
   0: bitwarden_rs::init_logging::{{closure}}
   1: std::panicking::rust_panic_with_hook
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:530
   2: rust_begin_unwind
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:437
   3: core::panicking::panic_fmt
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libcore/panicking.rs:85
   4: core::option::expect_none_failed
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libcore/option.rs:1269
   5: bitwarden_rs::main
   6: std::rt::lang_start::{{closure}}
   7: std::rt::lang_start_internal::{{closure}}
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/rt.rs:52
      std::panicking::try::do_call
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:348
      std::panicking::try
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:325
      std::panic::catch_unwind
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panic.rs:394
      std::rt::lang_start_internal
             at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/rt.rs:51
   8: main
   9: __libc_start_main
  10: <unknown>
Originally created by @okami-chen on GitHub (Aug 5, 2020). Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/1085 <!-- Please fill out the following template to make solving your problem easier and faster for us. This is only a guideline. If you think that parts are unneccessary for your issue, feel free to remove them. Remember to hide/obfuscate personal and confidential information, such as names, global IP/DNS adresses and especially passwords, if neccessary. --> ### Subject of the issue <!-- Describe your issue here.--> ### Your environment <!-- The version number, obtained from the logs or the admin page --> * Bitwarden_rs version: <!-- How the server was installed: Docker image / package / built from source --> * Install method: * Clients used: <!-- if applicable --> * Reverse proxy and version: <!-- if applicable --> * Version of mysql/postgresql: <!-- if applicable --> * Other relevant information: ### Steps to reproduce <!-- Tell us how to reproduce this issue. What parameters did you set (differently from the defaults) and how did you start bitwarden_rs? --> ### Expected behaviour <!-- Tell us what should happen --> ### Actual behaviour <!-- Tell us what happens instead --> ### Relevant logs <!-- Share some logfiles, screenshots or output of relevant programs with us. --> ``` [2020-08-05 14:20:17.397][panic][ERROR] thread 'main' panicked at 'Can't connect to DB: BadConnection("Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (2)")': src/main.rs:235 0: bitwarden_rs::init_logging::{{closure}} 1: std::panicking::rust_panic_with_hook at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:530 2: rust_begin_unwind at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:437 3: core::panicking::panic_fmt at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libcore/panicking.rs:85 4: core::option::expect_none_failed at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libcore/option.rs:1269 5: bitwarden_rs::main 6: std::rt::lang_start::{{closure}} 7: std::rt::lang_start_internal::{{closure}} at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/rt.rs:52 std::panicking::try::do_call at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:348 std::panicking::try at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panicking.rs:325 std::panic::catch_unwind at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/panic.rs:394 std::rt::lang_start_internal at /rustc/daecab3a784f28082df90cebb204998051f3557d/src/libstd/rt.rs:51 8: main 9: __libc_start_main 10: <unknown> ```
kerem closed this issue 2026-03-03 02:03:00 +03:00
Author
Owner

@BobWs commented on GitHub (Aug 10, 2020):

Had the same problem so out of the blue. Update the image to the latest version but that didn’t help. After the update BW wouldn’t start it was repeatedly restarting. Then I decided to restart my docker and that solved the problem.
But I guess this is not a normal behavior as I never had this problem before.

<!-- gh-comment-id:671236374 --> @BobWs commented on GitHub (Aug 10, 2020): Had the same problem so out of the blue. Update the image to the latest version but that didn’t help. After the update BW wouldn’t start it was repeatedly restarting. Then I decided to restart my docker and that solved the problem. But I guess this is not a normal behavior as I never had this problem before.
Author
Owner

@BlackDex commented on GitHub (Sep 14, 2020):

@BobWs , is MySQL also running as a container?
If that is the case it could be bitwarden is started before the MySQL container which causes this error and would en explain why a restart would work.

<!-- gh-comment-id:692297115 --> @BlackDex commented on GitHub (Sep 14, 2020): @BobWs , is MySQL also running as a container? If that is the case it could be bitwarden is started before the MySQL container which causes this error and would en explain why a restart would work.
Author
Owner

@BobWs commented on GitHub (Sep 17, 2020):

@BobWs , is MySQL also running as a container?

If that is the case it could be bitwarden is started before the MySQL container which causes this error and would en explain why a restart would work.

Yes Mariadb is also running as a container. I could set BW to depend-on the Mariadb container but I don’t know how to set it via CLi (command line)

<!-- gh-comment-id:693996919 --> @BobWs commented on GitHub (Sep 17, 2020): > @BobWs , is MySQL also running as a container? > > If that is the case it could be bitwarden is started before the MySQL container which causes this error and would en explain why a restart would work. Yes Mariadb is also running as a container. I could set BW to `depend-on` the Mariadb container but I don’t know how to set it via CLi (command line)
Author
Owner

@BlackDex commented on GitHub (Sep 17, 2020):

@BobWs Do you use docker compose?

<!-- gh-comment-id:694000881 --> @BlackDex commented on GitHub (Sep 17, 2020): @BobWs Do you use docker compose?
Author
Owner

@BlackDex commented on GitHub (Sep 17, 2020):

Because if so, please checkout this link: https://docs.docker.com/compose/startup-order/

<!-- gh-comment-id:694004827 --> @BlackDex commented on GitHub (Sep 17, 2020): Because if so, please checkout this link: https://docs.docker.com/compose/startup-order/
Author
Owner

@BobWs commented on GitHub (Sep 17, 2020):

@BobWs Do you use docker compose?

No I don’t I use CLi in combination with the GUI of Docker on a Synology. They have built a GUI for Docker. So most of the settings I can do via the GUI but sometimes I need more and use CLi. I have never tried docker compose.

<!-- gh-comment-id:694010134 --> @BobWs commented on GitHub (Sep 17, 2020): > @BobWs Do you use docker compose? No I don’t I use CLi in combination with the GUI of Docker on a Synology. They have built a GUI for Docker. So most of the settings I can do via the GUI but sometimes I need more and use CLi. I have never tried docker compose.
Author
Owner

@BlackDex commented on GitHub (Sep 17, 2020):

@BobWs Then it would be an option to add the following as a pre-start script for the docker.
A while back @jjlin created a way to have stuff done before bitwarden_rs gets started.
See: https://github.com/dani-garcia/bitwarden_rs/wiki/Starting-a-Container#customizing-container-startup

You could add a script which waits for mysql to be started like this (tested this on the testing image, not the alpine one).

while ! curl <mysql-db-ip>:3306 --output /dev/null -0 --connect-timeout 2 --max-time 2 ; do sleep 1 ; done
<!-- gh-comment-id:694084436 --> @BlackDex commented on GitHub (Sep 17, 2020): @BobWs Then it would be an option to add the following as a pre-start script for the docker. A while back @jjlin created a way to have stuff done before bitwarden_rs gets started. See: https://github.com/dani-garcia/bitwarden_rs/wiki/Starting-a-Container#customizing-container-startup You could add a script which waits for mysql to be started like this (tested this on the testing image, not the alpine one). ```bash while ! curl <mysql-db-ip>:3306 --output /dev/null -0 --connect-timeout 2 --max-time 2 ; do sleep 1 ; done ```
Author
Owner

@BobWs commented on GitHub (Sep 17, 2020):

@BobWs Then it would be an option to add the following as a pre-start script for the docker.
A while back @jjlin created a way to have stuff done before bitwarden_rs gets started.
See: https://github.com/dani-garcia/bitwarden_rs/wiki/Starting-a-Container#customizing-container-startup

You could add a script which waits for mysql to be started like this (tested this on the testing image, not the alpine one).

while ! curl <mysql-db-ip>:3306 --output /dev/null -0 --connect-timeout 2 --max-time 2 ; do sleep 1 ; done

Thanks for the suggestion I will give it a try and report back if it works.

<!-- gh-comment-id:694455799 --> @BobWs commented on GitHub (Sep 17, 2020): > @BobWs Then it would be an option to add the following as a pre-start script for the docker. > A while back @jjlin created a way to have stuff done before bitwarden_rs gets started. > See: https://github.com/dani-garcia/bitwarden_rs/wiki/Starting-a-Container#customizing-container-startup > > You could add a script which waits for mysql to be started like this (tested this on the testing image, not the alpine one). > > ```shell > while ! curl <mysql-db-ip>:3306 --output /dev/null -0 --connect-timeout 2 --max-time 2 ; do sleep 1 ; done > ``` Thanks for the suggestion I will give it a try and report back if it works.
Author
Owner

@dani-garcia commented on GitHub (Oct 3, 2020):

Commit 729c9cf might help if you need bitwarden_rs to retry the connection, by default it retries 15 times, one second between each try, then gives up, configurable by DB_CONNECTION_RETRIES (set to 0 for infinite retries).

<!-- gh-comment-id:703163900 --> @dani-garcia commented on GitHub (Oct 3, 2020): Commit 729c9cf might help if you need bitwarden_rs to retry the connection, by default it retries 15 times, one second between each try, then gives up, configurable by DB_CONNECTION_RETRIES (set to 0 for infinite retries).
Author
Owner

@BlackDex commented on GitHub (Nov 18, 2020):

Closing this ticket because of inactivity.
Feel free to re-open if the issue isn't resolved using the testing/master version.

<!-- gh-comment-id:729631259 --> @BlackDex commented on GitHub (Nov 18, 2020): Closing this ticket because of inactivity. Feel free to re-open if the issue isn't resolved using the `testing`/`master` version.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vaultwarden#768
No description provided.