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

latest beta mariadb error #3651

Closed
1 task done
adamaen87 opened this issue Jan 6, 2024 · 53 comments
Closed
1 task done

latest beta mariadb error #3651

adamaen87 opened this issue Jan 6, 2024 · 53 comments
Assignees
Labels
bug bw-unified-deploy An Issue related to Bitwarden unified deployment

Comments

@adamaen87
Copy link

Steps To Reproduce

I'am using bitwarden unified beta for month without problem. Since last beta there is a problem with mariadb connection.

Expected Result

everything fine :)

Actual Result

mariadb logs:
06/01/2024
17:47:24
2024-01-06 16:47:24 5 [Warning] Aborted connection 5 to db: 'bitwarden_vault' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
06/01/2024
17:47:24
2024-01-06 16:47:24 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
06/01/2024
17:47:47
and repeating every few seconds.
Same in bitwarden logs:
admin entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
exited: admin (terminated by SIGABRT (core dumped); not expected)

Screenshots or Videos

No response

Additional Context

I revert back to the 2023.12.0-beta image and no more error in both bitwarden and mariadb

Githash Version

b44cdc7-dirty

Environment Details

Debian 11 (OMV6 latest). Bitwarden and mariad in docker.

Database Image

mariadb:lts

Issue-Link

#2480

Issue Tracking Info

  • I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.
@adamaen87 adamaen87 added bug bw-unified-deploy An Issue related to Bitwarden unified deployment labels Jan 6, 2024
@JoeGTN1
Copy link

JoeGTN1 commented Jan 7, 2024

I'm getting the same issue. Here is the error in admin.log:

fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant');
      ALTER TABLE `Grant` DROP PRIMARY KEY;
Unhandled exception. MySqlConnector.MySqlException (0x80004005): Illegal mix of collations (utf8mb3_general_ci,IMPLICIT) and (utf8mb3_unicode_ci,IMPLICIT) for operation '='
   at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in /_/src/MySqlConnector/Core/ResultSet.cs:line 43
   at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 130
   at MySqlConnector.MySqlDataReader.CreateAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary`2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 468
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 56
   at MySqlConnector.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 296
   at MySqlConnector.MySqlCommand.ExecuteNonQuery() in /_/src/MySqlConnector/MySqlCommand.cs:line 107
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
   at Bit.MySqlMigrations.MySqlDbMigrator.MigrateDatabase(Boolean enableLogging, CancellationToken cancellationToken) in /source/util/MySqlMigrations/MySqlDbMigrator.cs:line 30
   at Bit.Admin.HostedServices.DatabaseMigrationHostedService.StartAsync(CancellationToken cancellationToken) in /source/src/Admin/HostedServices/DatabaseMigrationHostedService.cs:line 29
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Bit.Admin.Program.Main(String[] args) in /source/src/Admin/Program.cs:line 9

@DuckThom
Copy link

I've also been running into this issue on an upgrade from 2023.12.0 to 2024.1.0.

I just posted a comment in bitwarden/self-host aswell with some info: bitwarden/self-host#79

However, it looks like there are multiple problems occurring in the Grant table migrations. I've tried to undo some of the changes the migrations were making and it would seem like the original state of the table had the primary key on another column (I'm assuming Key, but i could be wrong here).

The first migration that is failing for me is running this query:

ALTER TABLE `Grant` ADD CONSTRAINT `PK_Grant` PRIMARY KEY (`Id`);

Error: Duplicate entry '0' for key 'Grant.PRIMARY'

This is because my Grant table is filled with rows and the previous migration runs this query:

ALTER TABLE `Grant` ADD `Id` int NOT NULL DEFAULT 0;

This sets all the values for the existing rows to 0, making it impossible to be a primary key as they have to be unique.

Because of the failing migration, the admin process crashes and supervisor restarts it. However, this will not undo the migrations that were already executed. So now when it tries to re-execute them, the primary key is already gone

ALTER TABLE `Grant` DROP PRIMARY KEY;

Error: Can't DROP 'PRIMARY'; check that column/key exists

I'm still debugging some more, but this is what I have found so far. To me the issue appears to be that since there are already items in the Grant table, the migrations are not able to be executed properly since the Id is not auto-incremented when it's added to the table.

@withinfocus
Copy link
Contributor

@adamaen87 can you pull the latest from main and give this a try? We made a modification to the database migration.

@adamaen87
Copy link
Author

adamaen87 commented Jan 12, 2024

Hello,

So, i just give a try and still have the same problem, but this time the container take much longer to start.

Bitwarden logs:

12/01/2024
07:43:00
addgroup: The GID 100' is already in use. 12/01/2024 07:43:00 Adding user bitwarden' ...
12/01/2024
07:43:00
Adding new user bitwarden' (1002) with group users' ...
12/01/2024
07:43:00
Not creating home directory `/home/bitwarden'.
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/admin.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/api.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/events.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/icons.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/identity.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/nginx.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/notifications.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/scim.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,997 INFO Included extra file "/etc/supervisor.d/sso.ini" during parsing
12/01/2024
07:45:10
2024-01-12 06:45:10,999 INFO RPC interface 'supervisor' initialized
12/01/2024
07:45:10
2024-01-12 06:45:10,999 CRIT Server 'unix_http_server' running without any HTTP authentication checking
12/01/2024
07:45:10
2024-01-12 06:45:10,999 INFO supervisord started with pid 1
12/01/2024
07:45:12
2024-01-12 06:45:12,000 INFO spawned: 'identity' with pid 63
12/01/2024
07:45:12
2024-01-12 06:45:12,001 INFO spawned: 'admin' with pid 64
12/01/2024
07:45:12
2024-01-12 06:45:12,002 INFO spawned: 'api' with pid 65
12/01/2024
07:45:12
2024-01-12 06:45:12,003 INFO spawned: 'icons' with pid 66
12/01/2024
07:45:12
2024-01-12 06:45:12,004 INFO spawned: 'nginx' with pid 67
12/01/2024
07:45:12
2024-01-12 06:45:12,005 INFO spawned: 'notifications' with pid 68
12/01/2024
07:45:27
2024-01-12 06:45:27,988 INFO success: identity entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:27
2024-01-12 06:45:27,989 INFO success: admin entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:27
2024-01-12 06:45:27,989 INFO success: api entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:27
2024-01-12 06:45:27,989 INFO success: icons entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:27
2024-01-12 06:45:27,989 INFO success: nginx entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:27
2024-01-12 06:45:27,989 INFO success: notifications entered RUNNING state, process has stayed up for > than 15 seconds (startsecs)
12/01/2024
07:45:35
2024-01-12 06:45:35,149 INFO exited: admin (terminated by SIGABRT (core dumped); not expected)
12/01/2024
07:45:36
2024-01-12 06:45:36,153 INFO spawned: 'admin' with pid 225

mariadb logs:

12/01/2024
07:45:34
2024-01-12 6:45:34 1980 [Warning] Aborted connection 1980 to db: 'bitwarden_vault' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
12/01/2024
07:45:34
2024-01-12 6:45:34 1978 [Warning] Aborted connection 1978 to db: 'unconnected' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
12/01/2024
07:45:57
2024-01-12 6:45:57 1984 [Warning] Aborted connection 1984 to db: 'bitwarden_vault' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
12/01/2024
07:45:57
2024-01-12 6:45:57 1982 [Warning] Aborted connection 1982 to db: 'unconnected' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
12/01/2024
07:46:21
2024-01-12 6:46:21 1988 [Warning] Aborted connection 1988 to db: 'bitwarden_vault' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)
12/01/2024
07:46:21
2024-01-12 6:46:21 1986 [Warning] Aborted connection 1986 to db: 'unconnected' user: 'bitwarden' host: '172.29.0.4' (Got an error reading communication packets)

Here is my compose file:

version: "3.8"
networks:
bitwarden:
name: bitwarden
mariadb:
external: true
services:
bitwarden:
container_name: bitwarden
env_file:
- settings.env
image: bitwarden/self-host:beta
networks:
- bitwarden
- mariadb
ports:
- "8043:8080"
restart: unless-stopped
volumes:
- CHANGE_TO_COMPOSE_DATA_PATH/bitwarden/config:/etc/bitwarden

I have also provided my settings file.
settings.txt

@DuckThom
Copy link

@adamaen87 I think the problem here is that your table is already been partially mutated. The migration executed the DROP PRIMARY KEY statement already but since it failed halfway through the migration, upon restart, Bitwarden is retrying the same migration steps even though some steps have executed already.

@withinfocus I think to fix the already mutated tables, they either have to be reverted to their pre-migration state (Id column removed and the PK re-added to where it used to be), or (some of) the migration steps need to be conditional, so they don't re-execute when the table has already been modified partially.

@withinfocus
Copy link
Contributor

The Entity Framework migration process shouldn't have applied a partial migration however and it'd roll back changes transactionally. Was something modified manually?

@DuckThom
Copy link

I did not make manual modifications prior to the crashing admin panel other than updating the tag in my docker compose yaml from 2023.12.0 to 2024.1.0 and then doing: docker compose pull && docker compose up -d

I'm also curious how exactly it would roll back as MySQL (and perhaps therefor also MariaDB) can't do a rollback on its own for DDL statements.

https://dev.mysql.com/doc/refman/8.0/en/cannot-roll-back.html

@withinfocus
Copy link
Contributor

You're correct, and the ID application is what went awry here. Pomelo cannot apply auto-increment immediately. Dropping the Id column and then recreating it like what's seen at

migrationBuilder.Sql("ALTER TABLE `Grant` ADD COLUMN `Id` INT AUTO_INCREMENT UNIQUE;");
migrationBuilder.AddPrimaryKey(
name: "PK_Grant",
table: "Grant",
column: "Id");
would be a likely patch.

@adamaen87
Copy link
Author

Nothing manually modified either.

@DuckThom
Copy link

@withinfocus I think so too. But what about the currently broken tables?
In the end I managed to fix mine by manually doing some queries to dump all Grant table data, re-add a primary key, remove the Id column and then import the data dump again to make the migration work from top-to-bottom again. If my originally broken table state is anything to go by, I'm assuming most people encountering this issue right now have a Grant table that has no PK and `Id` int NOT NULL DEFAULT '0'

CREATE TABLE `Grant` (
  `Key` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `Type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `SubjectId` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `SessionId` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `ClientId` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `Description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `CreationDate` datetime(6) NOT NULL,
  `ExpirationDate` datetime(6) DEFAULT NULL,
  `ConsumedDate` datetime(6) DEFAULT NULL,
  `Data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `Id` int NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

@withinfocus
Copy link
Contributor

We're gonna look into another migration edit that will inspect the state and partially patch as needed.

@kociubin
Copy link

FWIW I'm having the same issue. My production instance is no longer usable (users can't add new entries, can't login to bitwarden).

Is there a workaround we can try? Or should we restore from backup?

@adamaen87
Copy link
Author

FWIW I'm having the same issue. My production instance is no longer usable (users can't add new entries, can't login to bitwarden).

Is there a workaround we can try? Or should we restore from backup?

Hello, are you using docker? are you using the unfied-beta?
If so just use an older image, the last working for me is "2023.12.0-beta".

@kociubin
Copy link

FWIW I'm having the same issue. My production instance is no longer usable (users can't add new entries, can't login to bitwarden).
Is there a workaround we can try? Or should we restore from backup?

Hello, are you using docker? are you using the unfied-beta? If so just use an older image, the last working for me is "2023.12.0-beta".

Yes. I'm using docker / unified-beta. For now I restored from a backup (2024.1.1). It works fine and I'm planning to stay on this version until this issue is fixed.

@withinfocus
Copy link
Contributor

2024.1.2 includes #3668 that should resolve this issue for MySQL users.

@holow29
Copy link

holow29 commented Jan 18, 2024

@withinfocus Are you sure this is included in latest beta tag that is currently pushed to docker hub? Server version says 2024.1.2, but I am still getting the same error (as are a few others, it seems).

@adamaen87
Copy link
Author

@withinfocus Are you sure this is included in latest beta tag that is currently pushed to docker hub? Server version says 2024.1.2, but I am still getting the same error (as are a few others, it seems).

Same here with latest beta, no change still getting exactly same errors.

@withinfocus
Copy link
Contributor

I am speaking about images that are at that pull request merge time or newer is all, so commit-based ones or dev tags will get you the change. A full release to beta will come next week.

@kociubin
Copy link

Here is my experience. I noticed the issue when my docker container was at 2024.1.1. But I suspect the issue developed in one of the earlier builds (I update my docker images nightly in case of a 0-day fix).

To resolve it, I restored the container data files (i.e. MariaDB data files, bitwarden data files, etc) to a backup from 1/3/2024. I did this while keeping the docker image at 2024.1.1. The restore fixed the problem.

My suspicion is that one of the earlier builds left the database in a mangled state and could only be fixed by a db restore.

@withinfocus, does your fix in 2024.1.2 correct a potentially-mangled database caused by bug in an upgrade script in an earlier version? Or does it correct the script so the issue doesn't happen for new upgrades?

@withinfocus
Copy link
Contributor

Given the bug in the library we use there should have been an erroneous Id column that wasn't configured correctly, at least for those that ran that migration (that isn't transactional unfortunately by design with MySQL so the database is left in a broken state). The current script drops and recreates that column properly if it was there. No restore would be needed.

@RobTheBuilder2
Copy link

I am speaking about images that are at that pull request merge time or newer is all, so commit-based ones or dev tags will get you the change. A full release to beta will come next week.

I am experiencing the same issue. I pulled the dev docker image last night and still no change. Is there something I need to do to force the migration to re-execute?

@kociubin
Copy link

I also don't think the latest dev docker image fixes a broken database.

Steps:

  1. I restored my data files to an earlier backup that had the issue (i.e. broken database)
  2. Changed the image in docker compose file: image: bitwarden/self-host:dev

Still unable to login. The following errors are observed

==> admin.log <== 2024-01-19 08:27:14.665 -06:00 [ERR] Failed executing DbCommand (4ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30'] CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant'); ALTER TABLEGrantDROP PRIMARY KEY; 2024-01-19 08:27:37.730 -06:00 [INF] Migrating database. 2024-01-19 08:27:40.267 -06:00 [ERR] Failed executing DbCommand (4ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30'] CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant'); ALTER TABLEGrant` DROP PRIMARY KEY;

==> identity.log <==
2024-01-19 08:27:45.620 -06:00 [ERR] Failed executing DbCommand (1ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30']
SELECT o.Enabled, o.Id, o.Use2fa, o.UseEvents, o.UsersGetPremium, o.Use2fa AND (o.TwoFactorProviders IS NOT NULL) AS Using2fa, o.UseSso, o.UseKeyConnector, o.UseResetPassword, o.UseScim, o.UseCustomPermissions, o.UsePolicies, o.LimitCollectionCreationDeletion, o.AllowAdminAccessToAllCollectionItems, o.FlexibleCollections
FROM Organization AS o
2024-01-19 08:27:45.625 -06:00 [ERR] An exception occurred while iterating over the results of a query for context type 'Bit.Infrastructure.EntityFramework.Repositories.DatabaseContext'.
MySqlConnector.MySqlException (0x80004005): Unknown column 'o.FlexibleCollections' in 'field list'
`

@withinfocus
Copy link
Contributor

Based on that second log it looks like you're running newer code than what your migrations have caught up to.

My belief is that you have that Id column and it's set to be the primary key somehow but not with the correct auto-incrementing feature the platform needs. We're not sure how that happened as an interim state. You could attempt to drop that column manually:

ALTER TABLE `Grant` DROP COLUMN `Id`;

and see what happens. If your installation won't allow that, something a bit more advanced like:

ALTER TABLE `Grant` DROP PRIMARY KEY, ADD PRIMARY KEY `PK_Grant` (`Key`);

@kociubin
Copy link

I dropped the Id column. Still not working.

2024-01-19 11:20:56.241 -06:00 [INF] Migrating database.
2024-01-19 11:20:58.749 -06:00 [ERR] Failed executing DbCommand (4ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30']
CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant');
ALTER TABLE Grant DROP PRIMARY KEY;
2024-01-19 11:21:21.805 -06:00 [INF] Migrating database.

==> identity.log <==
2024-01-19 11:21:22.749 -06:00 [ERR] Failed executing DbCommand (3ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30']
SELECT o.Enabled, o.Id, o.Use2fa, o.UseEvents, o.UsersGetPremium, o.Use2fa AND (o.TwoFactorProviders IS NOT NULL) AS Using2fa, o.UseSso, o.UseKeyConnector, o.UseResetPassword, o.UseScim, o.UseCustomPermissions, o.UsePolicies, o.LimitCollectionCreationDeletion, o.AllowAdminAccessToAllCollectionItems, o.FlexibleCollections
FROM Organization AS o
2024-01-19 11:21:22.778 -06:00 [ERR] An exception occurred while iterating over the results of a query for context type 'Bit.Infrastructure.EntityFramework.Repositories.DatabaseContext'.
MySqlConnector.MySqlException (0x80004005): Unknown column 'o.FlexibleCollections' in 'field list'
at MySqlConnector.Core.ServerSession.ReceiveReplyAsyncAwaited(ValueTask1 task) in /_/src/MySqlConnector/Core/ServerSession.cs:line 962 at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in /_/src/MySqlConnector/Core/ResultSet.cs:line 43 at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 130 at MySqlConnector.MySqlDataReader.CreateAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 468

@withinfocus
Copy link
Contributor

Did you run the second suggested command?

@withinfocus
Copy link
Contributor

You don't need anything but the user-specific MariaDB password you configured as that user is what performs the migrations and has the right to execute that SQL.

@7djs7
Copy link

7djs7 commented Jan 22, 2024

@withinfocus awesome, it worked. I used mysql -h 172.31.0.2 -P 3306 --protocol=tcp -u bitwarden -p bitwarden_vault and put in my mariadb user password for docker compose then issued these commands
ALTER TABLE Grant DROP COLUMN Id; and then
ALTER TABLE GrantADD PRIMARY KEYPK_Grant (Key); and then
exit
And voila! Back to normal. Thank you again!!

@withinfocus
Copy link
Contributor

Glad it worked. MySQL is a little crazy for us sometimes, thus the "beta". We hope the library issue that broke this will be resolved one day.

@withinfocus withinfocus self-assigned this Jan 22, 2024
@7djs7
Copy link

7djs7 commented Jan 22, 2024

@withinfocus will we have to do this for each additional release update to the image?

@withinfocus
Copy link
Contributor

Definitely not -- this was just an integrity fix for what a prior migration broke. That migration should be marked as complete and normal upgrades will continue to operate as expected.

@RobTheBuilder2
Copy link

I can also confirm this works. I ran both commands against my MariaDB and I am back up and running. Thanks for the help!

@adamaen87
Copy link
Author

No luck for me. Stopped bitwarden container, ran both commands on mariadb, restarted bitwarden with latest beta and still the same errors. Reverted back to 2023.12.0-beta.

@holow29
Copy link

holow29 commented Jan 25, 2024

I am speaking about images that are at that pull request merge time or newer is all, so commit-based ones or dev tags will get you the change. A full release to beta will come next week.

@withinfocus Is the fix included in the latest 2024.1.2 self-host? (2024.1.2-beta)? I am still encountering the same error. I have not run any SQL manually because it is my understanding that a migration in your commits would fix the state of the database, and I felt like it would be beneficial to make sure the fix succeeded. I have only ever been on the beta images.

Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant');
      ALTER TABLE `Grant` DROP PRIMARY KEY;
Unhandled exception. MySqlConnector.MySqlException (0x80004005): Can't DROP INDEX `PRIMARY`; check that it exists

If the commits are included, it appears they are not sufficient to fix the state of the database/migration and this issue should be re-opened.

@withinfocus
Copy link
Contributor

The fix is there, but difficult to predict for a small numbers of users with the "when" of the 2024.1.x releases they may have used. You will need to execute some of the SQL above by hand for your intermediate state.

@holow29
Copy link

holow29 commented Jan 25, 2024

That is fine. I have decided to call it and execute the SQL above, which has solved it.

If your point is that perhaps operating certain beta tags that were not versioned releases may have messed up the migrations, that could be a reason I was still encountering issues. I have only ever operated the beta unified tags on this database, but I have used some that were in-between the versioned releases. In this case, it seems like the advice is to then "manually" fix DB for users like me.

Hopefully those that stuck with the versioned releases are solved by your migrations - however, I feel like the percentage of users that fall into this category is quite low, if that is even the case. My feeling is that most people using the unified beta have probably updated like me and will run into this issue - requiring either running this SQL themselves or having an actual fixed migration implemented. I'm not sure that is the "small number[s] of users" you speak of, but you would know better than I.

@kociubin
Copy link

FWIW, I'm one of those that have encountered the issue which didn't get fixed by upgrading to the latest beta. I had to manually run the SQL commands.

-From the beginning, I was running this: image: bitwarden/self-host:beta
-I was upgrading nightly by pulling the latest image
-I've never manually manipulated the underlying database

@adamaen87
Copy link
Author

@withinfocus
I still have the problem.
I have stopped bitwarden, executed the 2 SQL commands on the bitwarden database.
I have restarted bitwarden with latest beta and have this error:
2024-01-26 13:32:20.652 +00:00 [INF] Migrating database.
2024-01-26 13:32:21.821 +00:00 [ERR] Failed executing DbCommand (2ms) [Parameters=[], CommandType='"Text"', CommandTimeout='30']
CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Grant');
ALTER TABLE Grant DROP PRIMARY KEY;

@holow29
Copy link

holow29 commented Jan 26, 2024

@adamaen87 Did you execute

ALTER TABLE `Grant` ADD PRIMARY KEY `PK_Grant` (`Key`);

or

ALTER TABLE `Grant` DROP PRIMARY KEY, ADD PRIMARY KEY `PK_Grant` (`Key`);

Make sure whatever you run doesn't result in an error. I would try adding the primary key again.

@adamaen87
Copy link
Author

Yes, sorry, i was stupid, just after my post i understood that i just need to add primary key, as dropping give me an error.
Everything is working now with latest beta, thanks all for help.

@dk-armada
Copy link

dk-armada commented Jan 28, 2024

Can confirm.

ALTER TABLE `Grant` DROP COLUMN `Id`;
ALTER TABLE `Grant` ADD PRIMARY KEY `PK_Grant` (`Key`);

Fixes it.

@ruessda
Copy link

ruessda commented Feb 2, 2024

Had the same "problem" as @kociubin
I did
ALTER TABLE `Grant` DROP COLUMN `Id`;
and only the second part ...
ALTER TABLE `Grant` ADD PRIMARY KEY `PK_Grant` (`Key`);
Now it seems that everything is working again.
Thanks for your help.

Running this also fixes my issue.

How did you connect to the database? I get "mysql: command not found" when I try and connect to the database from the MariaDB container.

@FGSD15
Copy link

FGSD15 commented Feb 2, 2024

Had the same "problem" as @kociubin
I did
ALTER TABLE `Grant` DROP COLUMN `Id`;
and only the second part ...
ALTER TABLE `Grant` ADD PRIMARY KEY `PK_Grant` (`Key`);
Now it seems that everything is working again.
Thanks for your help.

Running this also fixes my issue.

How did you connect to the database? I get "mysql: command not found" when I try and connect to the database from the MariaDB container.

Get into the container, then you can run mariadb -u <username> -p (it'll then ask you for the user's password). Then you should be able to run those commands as needed.

@ruessda
Copy link

ruessda commented Feb 3, 2024

That worked, I ran the commands and restarted the database container. The aborted connection errors are gone from the logs but the container is still unhealthy and I see the following via Portainer relating to Maria-DB container health:

Last output/bin/sh: 1: mysqladmin: not found

Is there something else I need to do as well?

@FGSD15
Copy link

FGSD15 commented Feb 3, 2024

That I'm not sure about. MariaDB references that app here: https://mariadb.com/kb/en/mysqladmin/ but that sounds like an issue with how it's set up in portainer?

@dk-armada
Copy link

@ruessda mysqladmin has been deprecated. It has been replaced with mariadb-admin. You need to update your health checks.

@ruessda
Copy link

ruessda commented Feb 4, 2024

Thank you, changed DB health update and health check is now working and no errors in the log after running SQL commands. However I still cannot log in via web or mobile app. Fails on MFA. This stopped working prior to any troubleshooting and is what prompted me to start troubleshooting. I have a couple family members using this vault and they have the same issue. I can also create new users after changing disableUserRegistration and they cannot log in, fails on pw. Guessing this isn't related to the ID column issue. Anybody seen this issue?

Edit 1 - Note the error I receive is "An error has occurred. An unexpected error has occurred." If I enter an incorrect password or MFA token I get "Username or password is incorrect." and similar error when I type the wrong MFA code so it does appear auth is working.

Edit 2 - found resolution in BW community forum here: https://community.bitwarden.com/t/an-error-has-occurred-an-unexpected-error-has-occurred/62452/14
Switched to older image and everybody can log in again. Will wait for 24.1.3 before going back to current image setting. I am up and running again, thanks for everybody's help.

Edit 3 - going back image versions was only a temporary fix, issue is reoccurring (although I can still access mobile app). Still looking for a more permanent fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bw-unified-deploy An Issue related to Bitwarden unified deployment
Projects
None yet
Development

No branches or pull requests