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

Keycloak - Local execution issue #62

Closed
valentinacupac opened this issue Dec 29, 2022 · 4 comments
Closed

Keycloak - Local execution issue #62

valentinacupac opened this issue Dec 29, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@valentinacupac
Copy link
Owner

valentinacupac commented Dec 29, 2022

Keycloak works on GitHub Actions, but not locally when run on my machine.

This is the trace from my local machine - executing it from IntelliJ terminal. I use Windows.


PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:POSTGRES_URL='jdbc:postgresql://localhost:5432/banking_kata'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:POSTGRES_USER='postgres'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:POSTGRES_PASSWORD='admin'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:MONGO_INITDB_ROOT_USERNAME='rootuser'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:MONGO_INITDB_ROOT_PASSWORD='rootpass'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:ME_CONFIG_MONGODB_ADMINUSERNAME='rootuser'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:ME_CONFIG_MONGODB_ADMINPASSWORD='rootpass'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:ME_CONFIG_MONGODB_SERVER='mongodb'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:KEYCLOAK_REALM_URL='http://localhost:10000/auth/realms/banking-kata'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:KEYCLOAK_TEST_CLIENT_ID='test-client'
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> $env:KEYCLOAK_TEST_CLIENT_SECRET='B9N1WDFFMuZmYuEzXSbRC739YGaE7kb5'



PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> docker-compose up -d                                                     
Creating network "banking-kata-java_local" with the default driver
Creating network "banking-kata-java_default" with the default driver
Creating postgres      ... done
Creating mongo-express ... done
Creating mongodb       ... done
Creating keycloak      ... done
Creating adminer       ... done




PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> ./gradlew integrationTest

> Task :integrationTest

BankAccountControllerSystemTest > should_open_account_given_valid_request() FAILED
    org.springframework.web.reactive.function.client.WebClientRequestException at ExchangeFunctions.java:141
        Caused by: java.io.IOException at SocketDispatcher.java:-2
2022-12-29 15:11:51.310  INFO 16964 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-12-29 15:11:51.314  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-12-29 15:11:51.317  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2022-12-29 15:11:51.321  INFO 16964 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-12-29 15:11:51.322  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Shutdown initiated...
2022-12-29 15:11:51.324  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Shutdown completed.
2022-12-29 15:11:51.337  INFO 16964 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-12-29 15:11:51.337  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Shutdown initiated...
2022-12-29 15:11:51.339  INFO 16964 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Shutdown completed.

22 tests completed, 1 failed


The more detailed error is:

should_open_account_given_valid_request()

org.springframework.web.reactive.function.client.WebClientRequestException: An established connection was aborted by the software in your host machine; nested exception is java.io.IOException: An established connection was aborted by the software in your host machine
	at app//org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:141)
	at app//reactor.core.publisher.MonoErrorSupplied.subscribe(MonoErrorSupplied.java:55)

Caused by: java.io.IOException: An established connection was aborted by the software in your host machine
	at java.base/sun.nio.ch.SocketDispatcher.read0(Native Method)
	at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:46)

Also, I noticed that Keycloak randomly goes into restarting mode for me.
image

And I get these kinds of errors locally with Keycloak (logs via Docker)

14:22:00,823 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "metrics")]): java.lang.NullPointerException
	at org.wildfly.extension.metrics@25.0.1.Final//org.wildfly.extension.metrics.MetricsSubsystemAdd$2.execute(MetricsSubsystemAdd.java:91)
@valentinacupac valentinacupac added the bug Something isn't working label Dec 29, 2022
@valentinacupac
Copy link
Owner Author

valentinacupac commented Dec 29, 2022

@adrianliz the above is what I get when I run locally (i.e. works on GitHub Actions, but just issue for me locally), so I'm also interested how it looks for you when you run locally:

  1. Could you copy-paste the commands you run locally?
  2. Could you check in Docker, is the Keycloak container active after you start it, or does it randomly/frequently go into restart (like for me)?

@valentinacupac valentinacupac self-assigned this Dec 29, 2022
@valentinacupac
Copy link
Owner Author

valentinacupac commented Dec 29, 2022

@adrianliz I found out the root cause what's happening for me locally:

  • It seems that when docker-compose is ran on my local machine, that the 2 databases (banking_kata & keycloak) don't get created, and that is the root cause why the tests fail
  • When I go into the container and create the 2 databases manually via CLI, then all the integration tests pass
PS C:\Users\valen\GitHub\valentinacupac\banking-kata-java> docker-compose --env-file=.env.local up -d                                                            
Creating network "banking-kata-java_local" with the default driver                                                                                               
Creating network "banking-kata-java_default" with the default driver                                                                                             
Creating mongo-express ... done
Creating mongodb       ... done
Creating postgres      ... done
Creating keycloak      ... done
Creating adminer       ... done

I open up the CLI for the Docker container: postgres... this is the state, the 2 DB's are missing

/ # psql -U postgres;
psql (14.1)
Type "help" for help.

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(3 rows)

I run the tests, the tests then fail of course.

Then I manually create the 2 databases by manually typing out these commands in CLI

postgres=# CREATE DATABASE banking_kata OWNER postgres;
CREATE DATABASE
postgres=# CREATE DATABASE keycloak OWNER postgres;
CREATE DATABASE
postgres=# \l
                                  List of databases
     Name     |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
--------------+----------+----------+------------+------------+-----------------------
 banking_kata | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 keycloak     | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 postgres     | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
              |          |          |            |            | postgres=CTc/postgres
 template1    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
              |          |          |            |            | postgres=CTc/postgres
(5 rows)

postgres=#

And then all the integration tests pass

This means that the problem is just with me (this looks like just some local issue that I'll try to see what's the cause, why for me locally the 2 DB's don't get automatically created...)

Thanks for everything up to now; everything you did was correct, this issue that's appearing seems to be localized just for me.

valentinacupac added a commit that referenced this issue Dec 29, 2022
…apping due to potential interference with already installed (non-Docker) Postgres
valentinacupac added a commit that referenced this issue Dec 29, 2022
…apping due to potential interference with already installed (non-Docker) Postgres (updated ci.yaml)
valentinacupac added a commit that referenced this issue Dec 29, 2022
…apping due to potential interference with already installed (non-Docker) Postgres (updated ci.yaml)
@adrianliz
Copy link
Contributor

@valentinacupac I execute the following commands:

  • Only for Mac M1: ./src/main/resources/keycloak/build-keycloak-image-m1.zsh 16.0.0 to build an ARM compatible keycloak image.
  • Then, I execute docker-compose --env-file=.env.local down to remove previous containers.
  • After that, I execute docker-compose --env-file=.env.local up -d.
  • Finally, I execute ./gradlew integrationTest.

Note: I use --env-file=.env.local instead of harcoded environment variables to avoid related problems with new environment variables used in another environments.

I think that you have already found a solution.
Anyways, feel free if you have any problem!
Thanks.

@valentinacupac
Copy link
Owner Author

Thanks @adrianliz! Yes, I documented the workaround here #64 and I updated README file, the README file now contains only the Docker-based instructions, and also I moved the environment variables in the env folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants