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

Propagate JNDI context if none exists. Fixes that tasks submitted to executor during deployment are executed #24544

Merged
merged 4 commits into from
Aug 22, 2023

Conversation

OndroMih
Copy link
Contributor

@OndroMih OndroMih commented Aug 14, 2023

This addresses the conversation in #24539 (comment) and fixes #21087.

Changes the logic in ContextSetupProviderImpl to always store the invocation context for another thread, and then restore it only if needed. The application name is retrieved from the stored context, so it's always available and should never be null.

I also fixed the problem that appName was sometimes null by always copying the appName from the previous context to the new one.

Passes Concurrency TCK in appserver/tests/tck/concurrency. Passes tests in appserver/tests/admin and application. Although 2 tests failed when I ran locally, I rerun the tests individually and they passed. One in Concurrency TCK failed because GlassFish failed to start, one in Admin failed because it parsed the log file incorrectly (org.glassfish.main.admin.test.progress.DetachAttachITest) and expected a number where it was text.- Probably because of my slower machine there was some difference in the logs and possibly some extra log lines. I saw something similar in ProgressStatusComplexITest.java, which I fixed in this PR, but in DetachAttachITest.java it wasn't clear how to fix and running the test separately passed the test.


I also created a draft of a more complex improvement to execute the tasks after deployment is complete: #24540. There are multiple options

  • execute all tasks after deployment
  • execute only tasks submitted by scheduled executor after deployment but tasks submitted by plain executor immediately (the logic is tasks should be scheduled to execute after deployment and thus should be submitted by a scheduled executor)
  • support an option on the executor or deployment descriptor to switch the behavior - either execute immediately or execute after deployment completes.

Passes Concurrency TCK in appserver/tests/tck/concurrency.
Passes tests in appserver/tests/admin and application.
Signed-off-by:Ondro Mihalyi <[email protected]>
Passes Concurrency TCK in appserver/tests/tck/concurrency.
Passes tests in appserver/tests/admin and application.
Signed-off-by:Ondro Mihalyi <[email protected]>
@OndroMih
Copy link
Contributor Author

I see that some EJB tests failed. I’ll investigate why.

@avpinchuk
Copy link
Contributor

@OndroMih, build successful.

@OndroMih
Copy link
Contributor Author

@OndroMih, build successful.

Awesome 🙂

Copy link
Contributor

@dmatej dmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like black magic resolving old black magic, but if it works, I can say just WOW! :-)

}


/**
* Check whether the application component submitting the task is still running.
* Throw IllegalStateException if not.
*/
private boolean isApplicationEnabled(String appId) {
private void verifyApplicationEnabled(String appId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this method brings and always brought some fragility. It is completely heuristic, while we should rather use some lifecycle stages of the application to check where we are and what we can do .... sounds like sci-fi now :-)
I think there are also other places feeling this pain in GF.

Copy link
Contributor

@avpinchuk avpinchuk Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And second question: appId == null are illegal always or found some legal cases where it may be null? You always thow IllegalStateException.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before appId == null was legal when JNDI context was cleared or not propagated. Since I copy the value of appName into the context even in those cases, it should now never be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this method brings and always brought some fragility. It is completely heuristic, while we should rather use some lifecycle stages of the application to check where we are and what we can do .... sounds like sci-fi now :-)
I think there are also other places feeling this pain in GF.

I have a POC of a better solution here: #24544

There, I use an app lifecycle listener to trigger asynchrouns tasks after an app is deployed. We could extend that approach also to find out whether the application is enabled or being deployed. But even this PR reduces some magic - the appName is always present and the only magic now is that when the Application object doesn’t exist, it’s assumed that deployment is in progress.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But #24544 requires some more work to finalise the solution. It’s not a priority for me now, I raised it only to share the idea with you and store it for future. I’m going to work on some other fixes/improvements, which are more important now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OndroMih, we already it the #24544 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I’m on phone, I meant this PR: #24540

Copy link
Contributor

@dmatej dmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet those 1000 seconds.

@OndroMih
Copy link
Contributor Author

Yet those 1000 seconds.

Reverted now.

@dmatej dmatej added this to the 7.0.8 milestone Aug 21, 2023
@dmatej dmatej added the bug Something isn't working label Aug 21, 2023
@arjantijms arjantijms merged commit 6d56eba into eclipse-ee4j:master Aug 22, 2023
@OndroMih OndroMih changed the title Propagate JNDI context if none exists Propagate JNDI context if none exists. Fixes that tasks submitted to executor during deployment are executed Aug 23, 2023
@OndroMih OndroMih deleted the ondromih-initial-app-context branch October 29, 2023 07:30
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

Successfully merging this pull request may close these issues.

ManagedExecutorService does not execute tasks submitted during application startup
4 participants