sirixdb / sirix

SirixDB is an an embeddable, bitemporal, append-only database system and event store, storing immutable lightweight snapshots. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach.
https://sirix.io
BSD 3-Clause "New" or "Revised" License
1.13k stars 253 forks source link

Starting a rest-api service that fails to connect to keycloak exits with status code 0 #100

Open anmonteiro opened 5 years ago

anmonteiro commented 5 years ago
Full Stack Trace ``` io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:8080 at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.net.ConnectException: Connection refused ... 11 more Sep 28, 2019 11:28:52 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer SEVERE: Failed in deploying verticle io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:8080 at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.net.ConnectException: Connection refused ... 11 more io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:8080 at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:632) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.net.ConnectException: Connection refused ... 11 more ```

If the rest-api service fails to start due to keycloak not being available, it still exits with status code 0.

Expected behavior is a different status code.

I'm running into this while trying to wait for keycloak to be serving requests before starting up the web instance in docker-compose.

JohannesLichtenberger commented 5 years ago

Thanks, I might not have time to fix this today, but hopefully tomorrow evening

JohannesLichtenberger commented 5 years ago

And sorry that you're running into some troubles... hope you're still eager to give it a try :-)

JohannesLichtenberger commented 5 years ago

Hmm, BTW: What do you mean with the status code? The HTTP response error status code?

anmonteiro commented 5 years ago

Oh I meant exit code for the program. I must have been in a rush when I wrote this.

JohannesLichtenberger commented 5 years ago

Oh, okay, but I'm just using the Launcher:

https://github.com/sirixdb/sirix/blob/master/bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/Main.kt

Hmm, don't know how to change the exit code

anmonteiro commented 5 years ago

Feels like this should help https://github.com/eclipse-vertx/vert.x/issues/1401

JohannesLichtenberger commented 5 years ago

The Launcher should even be called directly from the fat jar:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>io.vertx.core.Launcher</Main-Class>
                    <Main-Verticle>${verticle.name}</Main-Verticle>
                  </manifestEntries>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                </transformer>
              </transformers>
              <artifactSet>
              </artifactSet>
              <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>

Maybe it's using the run-command:

  /**
   * Exits the JVM and indicate an issue during the Vert.x initialization.
   */
  public static void exitBecauseOfVertxInitializationIssue() {
    exit(VERTX_INITIALIZATION_EXIT_CODE);
  }

and this is calling

  /**
   * Exits the JVM with the given exit code.
   *
   * @param code the code, {@code 0} for success. By convention a non zero value if return to denotes an
   *             error.
   */
  public static void exit(int code) {
    System.exit(code);
  }

But I think in Kotlin it should probably be https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.system/exit-process.html

Not sure if I did something wrong or if it's a Vert.x Kotlin issue.

JohannesLichtenberger commented 5 years ago

But System.exit(int) should work I think.

JohannesLichtenberger commented 5 years ago

Oh BTW: Let's me know if you run into other bugs (if you still give it a try) :-)

JohannesLichtenberger commented 5 years ago

I changed some stuff in the Dockerfile and docker-compose file. If you change localhost to keycloak in sirix-conf.json and follow the instructions on https://sirix.io/rest-api.html it should be up and running. But regarding this particular error I don't really know :(

omkar-shitole commented 2 months ago

I think I faced a similar issue and may have a fix, as the workarounds I tried are working for me to overcome this particular error.

@anmonteiro were the stack traces you shared obtained while running docker-compose up via Windows machine, will you please confirm the traces below?

image

Below are the traces:

expand error trace ``` 2024-09-05 15:57:10 io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.19.0.2:8080 2024-09-05 15:57:10 Caused by: java.net.ConnectException: Connection refused 2024-09-05 15:57:10 at java.base/sun.nio.ch.Net.pollConnect(Native Method) 2024-09-05 15:57:10 at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) 2024-09-05 15:57:10 at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:1060) 2024-09-05 15:57:10 at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) 2024-09-05 15:57:10 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) 2024-09-05 15:57:10 at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) 2024-09-05 15:57:10 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) 2024-09-05 15:57:10 at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) 2024-09-05 15:57:10 at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) 2024-09-05 15:57:10 at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) 2024-09-05 15:57:10 at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) 2024-09-05 15:57:10 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 2024-09-05 15:57:10 at java.base/java.lang.Thread.run(Thread.java:1570) 2024-09-05 15:57:14 10:27:14.008 [vert.x-eventloop-thread-0] ERROR i.v.c.i.l.c.VertxIsolatedDeployer - Failed in deploying verticle 2024-09-05 15:57:14 io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.19.0.2:8080 2024-09-05 15:57:14 Caused by: java.net.ConnectException: Connection refused 2024-09-05 15:57:14 at java.base/sun.nio.ch.Net.pollConnect(Native Method) 2024-09-05 15:57:14 at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) 2024-09-05 15:57:14 at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:1060) 2024-09-05 15:57:14 at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) 2024-09-05 15:57:14 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) 2024-09-05 15:57:14 at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) 2024-09-05 15:57:14 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) 2024-09-05 15:57:14 at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) 2024-09-05 15:57:14 at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) 2024-09-05 15:57:14 at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) 2024-09-05 15:57:14 at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) 2024-09-05 15:57:14 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 2024-09-05 15:57:14 at java.base/java.lang.Thread.run(Thread.java:1570) 2024-09-05 15:57:17 10:27:17.540 [vert.x-eventloop-thread-0] ERROR i.v.c.i.l.c.VertxIsolatedDeployer - Failed in deploying verticle 2024-09-05 15:57:17 io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.19.0.2:8080 2024-09-05 15:57:17 Caused by: java.net.ConnectException: Connection refused 2024-09-05 15:57:17 at java.base/sun.nio.ch.Net.pollConnect(Native Method) 2024-09-05 15:57:17 at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) 2024-09-05 15:57:17 at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:1060) 2024-09-05 15:57:17 at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) 2024-09-05 15:57:17 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) 2024-09-05 15:57:17 at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) 2024-09-05 15:57:17 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) 2024-09-05 15:57:17 at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) 2024-09-05 15:57:17 at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) 2024-09-05 15:57:17 at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) 2024-09-05 15:57:17 at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) 2024-09-05 15:57:17 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 2024-09-05 15:57:17 at java.base/java.lang.Thread.run```
omkar-shitole commented 1 month ago

Hello @JohannesLichtenberger I've raised a PR to address the issue we've been discussing regarding line endings in shell scripts. This PR aims to enforce LF line endings for .sh files to prevent any potential cross-platform issues. With the changes included in PR, the container now starts correctly, ensuring that everything works as expected.

Here is the link to PR: https://github.com/sirixdb/sirix/pull/741

Docker Terminal