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

io.micronaut.context.exceptions.NoSuchBeanException while running on Github Actions #785

Closed
jurna opened this issue Dec 6, 2024 · 17 comments · Fixed by #812
Closed

io.micronaut.context.exceptions.NoSuchBeanException while running on Github Actions #785

jurna opened this issue Dec 6, 2024 · 17 comments · Fixed by #812

Comments

@jurna
Copy link

jurna commented Dec 6, 2024

Expected Behavior

Tests with test micronaut-test-resources should run on Github Actions

Actual Behaviour

While running github actions with test resources and mongodb repositories, github actions hangs. Logs contains some errors:

test-resources-service] 09:58:46.617 [main] INFO  i.m.c.DefaultApplicationContext$RuntimeConfiguredEnvironment - Established active environments: [test]
[test-resources-service] 09:58:46.633 [main] INFO  i.m.t.e.TestResourcesResolverLoader - Loaded 2 test resources resolvers: io.micronaut.testresources.mongodb.MongoDBTestResourceProvider, io.micronaut.testresources.testcontainers.GenericTestContainerProvider
[test-resources-service] 09:58:46.679 [pool-1-thread-1] INFO  o.testcontainers.DockerClientFactory - Testcontainers version: 2.7.0
[test-resources-service] 09:58:47.059 [pool-1-thread-1] INFO  o.t.d.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
[test-resources-service] 09:58:47.084 [pool-1-thread-1] INFO  o.testcontainers.DockerClientFactory - Docker host IP address is localhost
[test-resources-service] 09:58:47.102 [pool-1-thread-1] INFO  o.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 26.1.3
  API Version: 1.45
  Operating System: Ubuntu 22.04.5 LTS
  Total Memory: 7929 MB
[test-resources-service] 09:58:47.112 [pool-1-thread-1] INFO  o.testcontainers.images.PullPolicy - Image pull policy will be performed by: DefaultPullPolicy()
[test-resources-service] 09:58:47.114 [pool-1-thread-1] INFO  o.t.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
[test-resources-service] 09:58:47.140 [pool-1-thread-1] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling docker image: testcontainers/ryuk:0.9.0. Please be patient; this may take some time but only needs to be done once.
[test-resources-service] 09:58:48.168 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Starting to pull image
[test-resources-service] 09:58:48.183 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  0 pending,  0 downloaded,  0 extracted, (0 bytes/0 bytes)
[test-resources-service] 09:58:48.690 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  2 pending,  1 downloaded,  0 extracted, (8 KB/? MB)
[test-resources-service] 09:58:48.717 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  1 pending,  2 downloaded,  0 extracted, (118 KB/? MB)
[test-resources-service] 09:58:48.732 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  0 pending,  3 downloaded,  0 extracted, (118 KB/11 MB)
[test-resources-service] 09:58:48.854 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  0 pending,  3 downloaded,  1 extracted, (3 MB/11 MB)
[test-resources-service] 09:58:50.895 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  0 pending,  3 downloaded,  2 extracted, (4 MB/11 MB)
[test-resources-service] 09:58:50.950 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pulling image layers:  0 pending,  3 downloaded,  3 extracted, (11 MB/11 MB)
[test-resources-service] 09:58:50.963 [docker-java-stream--1467452668] INFO  tc.testcontainers/ryuk:0.9.0 - Pull complete. 3 layers, pulled in 2s (downloaded 11 MB at 5 MB/s)
[test-resources-service] 09:58:50.963 [pool-1-thread-1] INFO  tc.testcontainers/ryuk:0.9.0 - Image testcontainers/ryuk:0.9.0 pull took PT3.82284[41](https://github.com/Metasiteorg/demo-micronaut/actions/runs/12196727959/job/34024911875#step:5:42)54S
[test-resources-service] 09:58:50.984 [pool-1-thread-1] INFO  tc.testcontainers/ryuk:0.9.0 - Creating container for image: testcontainers/ryuk:0.9.0
[test-resources-service] 09:58:51.045 [pool-1-thread-1] INFO  tc.testcontainers/ryuk:0.9.0 - Container testcontainers/ryuk:0.9.0 is starting: 3240019e908960b6a6ce6c85b52d0ed71c2d600f91aa6382a6ee987d4b31ed25
[test-resources-service] 09:58:51.410 [pool-1-thread-1] INFO  tc.testcontainers/ryuk:0.9.0 - Container testcontainers/ryuk:0.9.0 started in PT0.[42](https://github.com/Metasiteorg/demo-micronaut/actions/runs/12196727959/job/34024911875#step:5:43)5696434S
Error: Exception in thread "main" io.micronaut.runtime.exceptions.ApplicationStartupException: Error starting Micronaut server: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. 
	at io.micronaut.runtime.Micronaut.handleStartupException(Micronaut.java:353)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:174)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:334)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:320)
	at io.micronaut.testresources.server.TestResourcesService.main(TestResourcesService.java:[43](https://github.com/Metasiteorg/demo-micronaut/actions/runs/12196727959/job/34024911875#step:5:44))
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. 
	at io.micronaut.context.DefaultBeanContext.newNoSuchBeanException(DefaultBeanContext.java:2798)
	at io.micronaut.context.DefaultApplicationContext.newNoSuchBeanException(DefaultApplicationContext.java:329)
	at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2761)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:17[45](https://github.com/Metasiteorg/demo-micronaut/actions/runs/12196727959/job/34024911875#step:5:46))
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:842)
	at io.micronaut.context.BeanLocator.getBean(BeanLocator.java:97)
	at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1831)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:360)
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:216)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:75)
	... 3 more
[test-resources-service] 09:58:[51](https://github.com/Metasiteorg/demo-micronaut/actions/runs/12196727959/job/34024911875#step:5:52).415 [pool-1-thread-1] INFO  o.t.utility.RyukResourceReaper - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
[test-resources-service] 09:58:51.415 [pool-1-thread-1] INFO  o.testcontainers.DockerClientFactory - Checking the system...
[test-resources-service] 09:58:51.415 [pool-1-thread-1] INFO  o.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
> Task :internalStartTestResourcesService

Steps To Reproduce

Create github actions job

name: Java CI with Gradle

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest
    permissions:
      contents: read

    steps:
    - uses: actions/checkout@v4
    - name: Set up JDK
      uses: actions/setup-java@v4
      with:
        java-version: '21'
        distribution: 'temurin'

    - name: Setup Gradle
      uses: gradle/actions/setup-gradle@v4

    - name: Build
      run: ./gradlew build

Environment Information

No response

Example Application

No response

Version

4.7.1

@jurna
Copy link
Author

jurna commented Dec 6, 2024

Micronaut version 4.6.1 works fine. Version 4.7.1 does not

@melix
Copy link
Collaborator

melix commented Dec 6, 2024

Can you share a reproducer? The https://github.com/Metasiteorg/demo-micronaut repo doesn't seem to be available.

@jurna
Copy link
Author

jurna commented Dec 9, 2024

Copied to public repo https://github.com/jurna/demo-micronaut

@jurna
Copy link
Author

jurna commented Dec 9, 2024

Strangely on my personal account github actions builds successfully. But on private organisation repo I have error mentioned above. Mabye some racing condition depending on how fast is the machine on which you are building?

@nareshpaturi
Copy link

nareshpaturi commented Dec 13, 2024

im also facing the same issue in github actions .Mine repo is in a private organization .

@nick-mcdowall
Copy link

I am also facing this issue, just tried again but on micronaut platform version 4.7.3:

Error: Exception in thread "main" io.micronaut.runtime.exceptions.ApplicationStartupException: Error starting Micronaut server: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. 
	at io.micronaut.runtime.Micronaut.handleStartupException(Micronaut.java:353)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:174)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:334)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:320)
	at io.micronaut.testresources.server.TestResourcesService.main(TestResourcesService.java:43)
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. 
	at io.micronaut.context.DefaultBeanContext.newNoSuchBeanException(DefaultBeanContext.java:2798)
	at io.micronaut.context.DefaultApplicationContext.newNoSuchBeanException(DefaultApplicationContext.java:329)
	at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2761)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1745)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:842)
	at io.micronaut.context.BeanLocator.getBean(BeanLocator.java:97)
	at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1831)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:3[60]
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:216)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:75)
	... 3 more

The current workaround is pinning the version to 4.6.3 for running via Github actions (private org repository).

@nick-mcdowall
Copy link

nick-mcdowall commented Jan 4, 2025

Update: I created a demo project to try and help find the cause of the issue above.

The interesting thing is that the visibility of the repo does seem to be significant. The workflow build/test works when the repo is public but failed when I made it private. This seems to be the case when using versions later than 4.6.3.

Logs when repo was public: success

Logs when the repo was made private: failure

(Note the repo is public again to make viewing the logs possible).

@melix
Copy link
Collaborator

melix commented Jan 7, 2025

That's an interesting discovery. At this stage I have no idea what could cause this. In both cases ryuk is started. There must be some environmental difference between the 2, which would disable a bean, but it's kind of surprising since test resources doesn't have environment dependent beans...

@mdeso
Copy link

mdeso commented Jan 8, 2025

We have the same problem and cannot update to 4.7.x because of this. As this changed in 4.7 there should be a commit that causes this. Has the ryuk version been updated?

@melix
Copy link
Collaborator

melix commented Jan 8, 2025

I don't think it's related to ryuk. It is started in both cases, and the error seems unrelated since it's a bean missing exception.

@melix
Copy link
Collaborator

melix commented Jan 9, 2025

Can you add this to your build.gradle file and let me know if it fixes the problem? I have made quite some tests, and it seems that the most probable explanation is that Micronaut Test Resources 4.7.0 depends on a buggy version of Micronaut Core. 2.7.1-SNAPSHOT seems to work for me:

repositories {
    maven {
        url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
        mavenContent {
            snapshotsOnly()
        }
    }
}
...
micronaut {
    ...
    testResources {
        version = "2.7.1-SNAPSHOT"
        ...
    }
}

@nick-mcdowall
Copy link

Can you add this to your build.gradle file and let me know if it fixes the problem? I have made quite some tests, and it seems that the most probable explanation is that Micronaut Test Resources 4.7.0 depends on a buggy version of Micronaut Core. 2.7.1-SNAPSHOT seems to work for me:

repositories {
    maven {
        url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
        mavenContent {
            snapshotsOnly()
        }
    }
}
...
micronaut {
    ...
    testResources {
        version = "2.7.1-SNAPSHOT"
        ...
    }
}

This looks promising! - I ran in public and private mode and both succeeded 🥳 .

@melix
Copy link
Collaborator

melix commented Jan 9, 2025

Great! I need to investigate another issue (builds hanging when test resources fail to load) then I'll release 2.7.1. Thanks for your patience!

melix added a commit that referenced this issue Jan 10, 2025
If the server factory fails to start the test resources service, then
we'd wait indefinitely for the server port file to appear, which
causes builds to hang.

Closes #785
melix added a commit that referenced this issue Jan 10, 2025
If the server factory fails to start the test resources service, then
we'd wait indefinitely for the server port file to appear, which
causes builds to hang.

Closes #785
melix added a commit that referenced this issue Jan 10, 2025
If the server factory fails to start the test resources service, then
we'd wait indefinitely for the server port file to appear, which
causes builds to hang.

Closes #785
@melix
Copy link
Collaborator

melix commented Jan 13, 2025

Please try to upgrade to Micronaut Gradle plugins 4.4.5, which will use latest test resources, and let me know if the issue is fixed for you, thanks!

@nick-mcdowall
Copy link

Thanks @melix, will do!

I assumed we would also need the micronaut-platform to be updated to reference the latest test-resources or does the plugin override that?

@melix
Copy link
Collaborator

melix commented Jan 13, 2025

The plugin does the job, the version in the platform is only used by the Maven plugin .

@nick-mcdowall
Copy link

ok looks good on my side in the demo project 🙏 ( private repo with gradle plugins at 4.4.5 and micronaut-platform at 4.7.4). Thanks for resolving @melix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants