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

Thread locked with optimize-contexts and @Startup bean #38040

Closed
lucaspouzac opened this issue Jan 4, 2024 · 5 comments
Closed

Thread locked with optimize-contexts and @Startup bean #38040

lucaspouzac opened this issue Jan 4, 2024 · 5 comments
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working

Comments

@lucaspouzac
Copy link

Describe the bug

Since migration to quarkus 3.6.x, our application don't startup because a thread is locked.

It's related to this feature : #36626

If we set quarkus.arc.optimize-contexts=false, the application start correctly.

Expected behavior

If we set quarkus.arc.optimize-contexts=true, the application start correctly.

Actual behavior

No response

How to Reproduce?

Attached, an application with 2 tests.

  • 1 test that works correctly: OptimizeContextsDisabledTest
  • 1 test that fails: OptimizeContextsEnabledTest

optimize-contexts.tar.gz

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@lucaspouzac lucaspouzac added the kind/bug Something isn't working label Jan 4, 2024
@gsmet gsmet added area/arc Issue related to ARC (dependency injection) and removed triage/needs-triage labels Jan 4, 2024
Copy link

quarkus-bot bot commented Jan 4, 2024

/cc @Ladicek (arc), @manovotn (arc), @mkouba (arc)

@gsmet
Copy link
Member

gsmet commented Jan 4, 2024

@mkouba could you check it's the same issue that you already solved or if it's different?

@mkouba
Copy link
Contributor

mkouba commented Jan 5, 2024

@mkouba could you check it's the same issue that you already solved or if it's different?

I can confirm that it's the same kind of problem and I've just verified that #37982 fixed this problem. In this particular case, an external service is called in the bean constructor (the rest client offloads the execution to a different thread ) which has the same effect as if it was called in a @PostConstruct callback a la #37958.

@mkouba
Copy link
Contributor

mkouba commented Jan 5, 2024

@lucaspouzac another workaround is to use a @Startup method or an observer method instead of the bean constructor:

@ApplicationScoped
public class BootService {
    private final ConfigService configService;

    @Inject
    public BootService(@RestClient ConfigService configService) {
        this.configService = configService;
    }

    @Startup
    void onStart() {
       // Sync for startup
       updateCache().await().atMost(Duration.ofSeconds(1));
    }

    Uni<Void> updateCache() {
        return configService.getConfiguration().chain(item -> Uni.createFrom().voidItem());
    }
}

mkouba added a commit to mkouba/quarkus that referenced this issue Jan 5, 2024
- fixes quarkusio#37958 and quarkusio#38040
- use a separate lock for each bean in the generated ContextInstances
- replace ContextInstances#forEach() and ContextInstances#clear() with
  ContextInstances#removeEach()
- optimize the generated ContextInstances to significantly reduce the
  size of the generated bytecode
mkouba added a commit to mkouba/quarkus that referenced this issue Jan 5, 2024
- fixes quarkusio#37958 and quarkusio#38040
- use a separate lock for each bean in the generated ContextInstances
- replace ContextInstances#forEach() and ContextInstances#clear() with
  ContextInstances#removeEach()
- optimize the generated ContextInstances to significantly reduce the
  size of the generated bytecode
@mkouba
Copy link
Contributor

mkouba commented Jan 10, 2024

Fixed in #37982 and backported in #38069.

@mkouba mkouba closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants