# Keycloak with MariaDB Galera Cluster crashes every time something DB write happens

# Conclusion

--transaction-xa-enabled=false option is necessary

# environment

  • keycloak: 20.0.1
  • OpenJDK: openjdk-11-jdk:amd64
  • MariaDB: 10.3.36-MariaDB-0+deb10u2 Debian 10
  • Galera Cluster: wsrep_provider_version = 3.25(rddf9876)

#What has happened For example, the very first of using when creating admin account it crashed, but restarted I see that the admin account is created normally. Then create a realm crash again. It seems that DB writing was succeeded but keacloak crash at the time when persistent data is likely to be saved, it is a very interesting behavior.

The keycloak log is as follows:

2022-12-13 09:47:46,413 WARN  [com.arjuna.ats.jta] (executor-thread-2) ARJUNA016039: onePhaseCommit on < formatId=131077, gtrid_length=35, bqual_length=36, tx_uid=0:ffff0a44d623:a13a:6397cb77:e1, node_name=quarkus, branch_uid=0:ffff0a44d623:a13a:6397cb77:e4, subordinatenodename=null, eis_name=0 > (io.agroal.narayana.BaseXAResource@70337290) failed with exception ARJUNA016099: Unknown error code:0: javax.transaction.xa.XAException: (conn=42) Socket error
	at org.mariadb.jdbc.MariaDbPoolConnection$MariaDbXAResource.mapXaException(MariaDbPoolConnection.java:190)
	at org.mariadb.jdbc.MariaDbPoolConnection$MariaDbXAResource.execute(MariaDbPoolConnection.java:200)
	at org.mariadb.jdbc.MariaDbPoolConnection$MariaDbXAResource.commit(MariaDbPoolConnection.java:206)

Warnings are issued when trying to commit to XAResource. Looking more

2022-12-13 09:47:46,507 WARN  [io.agroal.pool] (executor-thread-2) Datasource '<default>': (conn=42) Connection is closed
2022-12-13 09:47:46,960 WARN  [com.arjuna.ats.jta] (executor-thread-2) ARJUNA016061: TransactionImple.enlistResource - XAResource.start returned: XAException.XAER_RMFAIL for < formatId=131077, gtrid_length=35, bqual_length=36, tx_uid=0:ffff0a44d623:a13a:6397cb77:e9, node_name=quarkus, branch_uid=0:ffff0a44d623:a13a:6397cb77:ec, subordinatenodename=null, eis_name=0 >: javax.transaction.xa.XAException: Error trying to start xa transaction: (conn=41) Socket error

XAResource can't be started?

2022-12-13 09:47:46,973 WARN  [com.arjuna.ats.jta] (executor-thread-2) ARJUNA016138: Failed to enlist XA resource io.agroal.narayana.BaseXAResource@48874761: javax.transaction.xa.XAException: Error trying to start xa transaction: (conn=41) Socket error
2022-12-13 09:47:46,974 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (executor-thread-2) SQL Error: 0, SQLState: null
2022-12-13 09:47:46,977 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (executor-thread-2) Deferred enlistment not supported

I wonder why distributed transaction XA comes out when only one DB is used, althoug somehow the problem seems to be related to XA

So, when I read a guide of the keycloak Configuring the database (opens new window), there is a section Using Database Vendors without XA transaction support, and I find " Add --transaction-xa-enabled=false when using Azure SQL, MariaDB Galera, or DBMS that doesn't support XA."

Huh, Galera didn't support distributed transactions? I looked into it, it was certainly written in Known Issues (opens new window)

I'm always worried about my ignorant, so I was happy to have more knowledge like this. And the Keycloak is up and running (which is the main reason for the joy?)

# references

Last Updated: 1/8/2023, 4:39:23 AM