question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keycloak-x - unable to modify mssql/SQLServer port to anything other than 1433

See original GitHub issue

Describe the bug

Setting the KC_DB_URL_PORT environment variable does not work. The default of 1433 is retained when keycloak attempts to connect to the database.

Version

17.0.1

Expected behavior

Specifying the environment property KC_DB_URL_PORT should be honored. Keycloak should try to establish it’s database connections using that port.

Actual behavior

Here is the error that shows up at startup:

2022-04-12 13:46:09,475 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread: keycloak-default) HHH000342: Could not obtain connection to query metadata: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host my-mssql.db, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234) at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:285) at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2431) at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:656) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2440) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2103) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1950) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1162) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:735) at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:210) at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:513) at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:494) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:75) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1126) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)

How to Reproduce?

Here is the relevant section of the chart yaml’s env I am using to specify the database properties.

        env:
            - name: KC_DB
              value: mssql
            - name: KC_DB_URL_HOST
            - value: my-mssql.db
            - name: KC_DB_URL_PORT
              value: "1443"
            - name: KC_DB_DATABASE
              value: keycloak
            - name: KC_TRANSACTION_XA_ENABLED
               value: "false"
             ....

Start the container as such

  command:
    - "/opt/keycloak/bin/kc.sh"
    - "--verbose"
    - "start"
    - "--auto-build"

Anything else?

The dbchecker honors the property just fine. It appears that the port is hardcoded to 1433 in org.keycloak.quarkus.runtime.storage.database.Database. Reviewing that file suggests the problem would be true of other databases…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pedroigorcommented, Apr 12, 2022

Yeah, I think so. We do have options for host and database. Having an option to set the port should make the config more consistent.

0reactions
nvp152commented, Apr 13, 2022

Thanks for the quick turn around

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the 1433 default port on the MS SQL Server for ...
1. Change the port in the SQL Server Configuration Manager, and under the TCP/IP which has the layer of the IP v4 ,...
Read more >
Configure a Server to Listen on a Specific TCP Port - SQL Server
... SQL Server Configuration Manager to configure the Database Engine to listen on a specific fixed port other than the default port, 1433....
Read more >
Change the Default Port Number (TCP/1433) for a MS SQL ...
The default SQL Server instance (MSSQLSERVER) uses static TCP port 1433. It is the port the clients or SQL Server Management Studio (SSMS) ......
Read more >
Keycloak 18.0.0 released
You can now change the port of your jdbc connection string explicitly ... unable to modify mssql/SQLServer port to anything other than 1433...
Read more >
Why SQL Server port number is not default 1433?
If the named instance is the only instance of the Database Engine installed, it will probably use TCP port 1433. If other instances...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found