Keycloak quarkus container remote debug fails with "java.net.SocketException: Connection reset"

1,954 views
Skip to first unread message

Gunter Zeilinger

unread,
May 4, 2022, 7:16:20 AM5/4/22
to Keycloak User
Launch container with start-dev --debug:

$ docker run -p8787:8787 --name=keycloak --rm quay.io/keycloak/keycloak:18.0.0 start-dev --debug
Listening for transport dt_socket at address: 8787
Updating the configuration and installing your custom providers, if any. Please wait.
2022-05-04 10:59:46,900 INFO  [io.quarkus.deployment.QuarkusAugmentor] (main) Quarkus augmentation completed in 7447ms
Listening for transport dt_socket at address: 8787
2022-05-04 10:59:49,108 INFO  [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: FrontEnd: <request>, Strict HTTPS: false, Path: <request>, Strict BackChannel: false, Admin: <request>, Port: -1, Proxied: false
2022-05-04 10:59:49,663 WARN  [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
2022-05-04 10:59:49,685 WARN  [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal
2022-05-04 10:59:49,693 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller'
2022-05-04 10:59:49,817 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.8.Final
2022-05-04 10:59:50,086 INFO  [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_801167, Site name: null
2022-05-04 10:59:51,001 INFO  [org.keycloak.quarkus.runtime.storage.database.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml
2022-05-04 10:59:52,746 INFO  [org.keycloak.services] (main) KC-SERVICES0050: Initializing master realm
2022-05-04 10:59:53,725 INFO  [io.quarkus] (main) Keycloak 18.0.0 on JVM (powered by Quarkus 2.7.5.Final) started in 6.387s. Listening on: http://0.0.0.0:8080
2022-05-04 10:59:53,725 INFO  [io.quarkus] (main) Profile dev activated.
2022-05-04 10:59:53,725 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, jdbc-mariadb, jdbc-mssql, jdbc-mysql, jdbc-oracle, jdbc-postgresql, keycloak, narayana-jta, reactive-routes, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-metrics, vault, vertx]
2022-05-04 10:59:53,729 WARN  [org.keycloak.quarkus.runtime.KeycloakMain] (main) Running the server in development mode. DO NOT use this configuration in production.


Try to connect with jdb:

$ jdb -attach localhost:8787
java.net.SocketException: Connection reset
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136)
    at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:255)
    at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
    at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
    at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
    at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
    at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
    at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1095)

Fatal error:
Unable to attach to target VM.


Starting Keycloak Quarkus outside the conatiner, attaching works:

$ ~/keycloak-18.0.0/bin/kc.sh start-dev --debug
Listening for transport dt_socket at address: 8787
Listening for transport dt_socket at address: 8787
2022-05-04 13:14:53,755 INFO  [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: FrontEnd: <request>, Strict HTTPS: false, Path: <request>, Strict BackChannel: false, Admin: <request>, Port: -1, Proxied: false
2022-05-04 13:14:54,198 WARN  [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal
2022-05-04 13:14:54,258 WARN  [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
2022-05-04 13:14:54,276 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller'
2022-05-04 13:14:54,399 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.8.Final
2022-05-04 13:14:54,679 INFO  [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (main) Node name: node_588300, Site name: null
2022-05-04 13:14:54,957 INFO  [io.quarkus] (main) Keycloak 18.0.0 on JVM (powered by Quarkus 2.7.5.Final) started in 2.913s. Listening on: http://0.0.0.0:8080
2022-05-04 13:14:54,957 INFO  [io.quarkus] (main) Profile dev activated.
2022-05-04 13:14:54,957 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, jdbc-mariadb, jdbc-mssql, jdbc-mysql, jdbc-oracle, jdbc-postgresql, keycloak, narayana-jta, reactive-routes, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-health, smallrye-metrics, vault, vertx]
2022-05-04 13:14:54,960 WARN  [org.keycloak.quarkus.runtime.KeycloakMain] (main) Running the server in development mode. DO NOT use this configuration in production.

$ jdb -attach localhost:8787
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>

tuzar...@gmail.com

unread,
Oct 6, 2022, 8:27:34 AM10/6/22
to Keycloak User
Any updates on this?

Simon Levermann

unread,
Oct 6, 2022, 9:15:30 AM10/6/22
to Keycloak User
I think the issue is that the debug port is only binding to the local interface in the docker network, and it's not bound to the external network interface. Try setting -e DEBUG_PORT=*:8787"  as an environment variable via docker so that it binds on all interfaces instead. Then, with the -p 8787:8787, you should be able to attach your local debugger.

Best,
Simon

Gunter Zeilinger

unread,
Oct 7, 2022, 6:07:57 AM10/7/22
to Keycloak User
Right, solved it by

ENV DEBUG_PORT=*:8787

Reply all
Reply to author
Forward
0 new messages