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

Block contextual operations from lazily enlisting CDI beans #8348

Merged

Conversation

aguibert
Copy link
Contributor

Intermediate solution to the MP Context Propagation issue identified here:
eclipse/microprofile-context-propagation#167

@LibbyBot
Copy link

Code analysis and actions

DO NOT DELETE THIS COMMENT.
  • 7 product code files were changed.

  • Please describe in a separate comment how you tested your changes.

  • 2 FAT files were changed, added, or removed.

  • Check that the build did not break the affected FAT suite(s).

  • 2 messages files were changed and need an L2 review.

  • @OpenLiberty/message-reviewer Please review.

  • dev/com.ibm.ws.concurrent.mp.1.0/resources/com/ibm/ws/concurrent/mp/resources/CWWKCMessages.nlsprops

  • dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops

  • 2 NLS files were changed and need an ID review.

  • @OpenLiberty/message-reviewer Please review.

  • dev/com.ibm.ws.concurrent.mp.1.0/resources/com/ibm/ws/concurrent/mp/resources/CWWKCMessages.nlsprops

  • dev/com.ibm.ws.cdi.mp.context/resources/com/ibm/ws/cdi/mp/context/resources/CDI_MP_CONTEXT.nlsprops

# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
#CMVCPATHNAME com.ibm.ws.concurrent/resources/com/ibm/ws/concurrent/resources/CWWKCMessages.nlsprops
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this commented line matters, but com.ibm.ws.concurrent should be switched to com.ibm.ws.cdi.mp.context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't matter, it just can't be blank


# do not translate: CDI, CompletionStage
CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E: CDI beans used in contextual operations, such as a CompletionStage, must be accessed using a CDI bean operation, such as a public \
method, before context for the operation is captured. The CDI beans that were not accessed before context was captured are: {0}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to state this directly in terms of what the user must do to fix the problem? For example,
"You must access CDI beans {0} prior to capturing context for the contextual action or task in order for the CDI beans to behave correctly when accessed from the action or task."
The way it is currently written makes it less clear that it is the user's/application's responsibility to take action to fix it.

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 want to have {0} at the end of the message because it can get very long, because ContextualInstance toString() includes lots of information such as what qualifiers are on the bean. Also, a large list of beans could be provided.

I could change the last sentence from:
The CDI beans that were not accessed before context was captured are: {0}
to be:
The following CDI beans must be accessed before capturing context: {0}
to make it more clear what action the user needs to take

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine to put the list at the end. However, my comment about writing this more directly and including the word "you" still applies. Maybe we could combine the two?

"You must access CDI beans prior to capturing context for the contextual action or task in order for the CDI beans to behave correctly when accessed from the action or task. The following CDI beans must be accessed before capturing context: {0}."

It would be good to get the ID reviewer involved here to tell us what we can and cannot say in a message, and they may have some ideas for improving clarity as well.

@@ -68,6 +68,12 @@ public void run() {
try {
if (contextApplied != null)
threadContextDescriptor.taskStopping(contextApplied);
} catch (RuntimeException x) {
// prioritize surfacing an actual task failure over a failure clearing context
Copy link
Contributor

Choose a reason for hiding this comment

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

If we switch the prioritization in ContextualRunnable, we should do so in every other contextual action type as well (Function, BiFunction, Consumer, Supplier, ...). That said, I'm not convinced that we ought to switch the ordering. A failure to clear context is very severe, and typically would be more important than a task's own exception (which might even sometimes be expected). I would argue that also applies in the case for which these changes are being added.

}
}
assertTrue("CompletableFuture should have been marked done", cf.isDone());
assertTrue("CompletableFuture should have been marked as completex exceptionally", cf.isCompletedExceptionally());
Copy link
Contributor

Choose a reason for hiding this comment

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

minor typo: completex -> completed

@skasund
Copy link

skasund commented Jul 25, 2019

L2 message review complete

Copy link
Contributor

@ManasiGandhi ManasiGandhi left a comment

Choose a reason for hiding this comment

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

Suggested some minor changes.

#
# NLS_MESSAGEFORMAT_VAR
#
# Strings in this file which contain replacement variables are processed by the MessageFormat
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
'Strings in this file which contain replacement variables are processed by the MessageFormat # class (single quote must be coded as 2 consecutive single quotes '').'
to
'Strings in this file, which contain replacement variables, are processed by the MessageFormat #class (single quotation mark must be coded as two consecutive single quotation marks '').'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a boilerplate header comment (not an NLS message) so I'm going to leave as-is. Any line that starts with # in a .nlsprops file is a comment and a user will never see it

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

# NLS_MESSAGEFORMAT_VAR
#
# Strings in this file which contain replacement variables are processed by the MessageFormat
# class (single quote must be coded as 2 consecutive single quotes ''). Strings in this file
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
'Strings in this file, which do NOT contain replacement variables are NOT processed by the MessageFormat class'
to
'Strings in this file, which do NOT contain replacement variables are NOT processed by the MessageFormat class (single quotation mark must be coded as one single quote '). '
(single quote must be coded as one single quote '). '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a boilerplate header comment (not an NLS message) so I'm going to leave as-is. Any line that starts with # in a .nlsprops file is a comment and a user will never see it

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

# (single quote must be coded as one single quote ').

# This message bundle does not have its own message range, and instead reserves specific error messages from the
# com.ibm.ws.concurrent.mp.1.0 message bundle
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
' This message bundle does not have its own message range, and instead reserves specific error messages from the com.ibm.ws.concurrent.mp.1.0 message bundle'.
to
'This message bundle does not have its own message range. Instead, it reserves specific error messages from the com.ibm.ws.concurrent.mp.1.0 message bundle '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a boilerplate header comment (not an NLS message) so I'm going to leave as-is. Any line that starts with # in a .nlsprops file is a comment and a user will never see it

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.


# do not translate: CDI, CompletionStage
CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E: CDI beans used in contextual operations, such as a CompletionStage, must be accessed using a CDI bean operation, such as a public \
method, before context for the operation is captured. The CDI beans that were not accessed before context was captured are: {0}
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
'CDI beans used in contextual operations, such as a CompletionStage, must be accessed using a CDI bean operation, such as a public method, before context for the operation is captured. The CDI beans that were not accessed before context was captured are: {0} '
to
' CDI beans used in contextual operations, such as a CompletionStage, must be accessed by using a CDI bean operation, such as a public method, before context for the operation is captured. The CDI beans that were not accessed before the context was captured are: {0} '

@aguibert
Copy link
Contributor Author

#build

@LibbyBot
Copy link

Your personal build request is at https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_KWl_YK7uEemoaqXqE6v4jQ

Target locations of links might be accessible only to IBM employees.

@LibbyBot
Copy link

@njr-11
Copy link
Contributor

njr-11 commented Jul 26, 2019

#build

@LibbyBot
Copy link

Your personal build request is at https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_8GicEK-bEemoaqXqE6v4jQ

Target locations of links might be accessible only to IBM employees.

@LibbyBot
Copy link

@aguibert aguibert force-pushed the mpConcurrent-block-cdi-lazy-enlist branch from 1720ee8 to 1404ad8 Compare July 28, 2019 19:40
@aguibert
Copy link
Contributor Author

#build

@LibbyBot
Copy link

Your personal build request is at https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_LdmKELFnEemoaqXqE6v4jQ

Target locations of links might be accessible only to IBM employees.

@LibbyBot
Copy link

@LibbyBot
Copy link

The build aguibert-8348-20190728-1947
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_LdmKELFnEemoaqXqE6v4jQ
completed successfully!

@aguibert aguibert merged commit 6f172e2 into OpenLiberty:integration Jul 29, 2019
Copy link
Contributor

@ManasiGandhi ManasiGandhi left a comment

Choose a reason for hiding this comment

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

A few additional proposed changes.


# do not translate: CDI, CompletionStage
CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E:You must access CDI beans prior to capturing context for the contextual action or task in order for the CDI \
beans to behave correctly when accessed from the action or task. The following CDI beans must be accessed before capturing context: {0}.
Copy link
Contributor

@ManasiGandhi ManasiGandhi Aug 1, 2019

Choose a reason for hiding this comment

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

Change
'You must access CDI beans prior to capturing context for the contextual action or task in order for the CDI \ beans to behave correctly when accessed from the action or task. The following CDI beans must be accessed before capturing context: {0}.'
to
'The following CDI beans were not accessed before the context was captured: {0}. You must access the CDI beans before context is captured for the contextual action or task so that the CDI beans behave correctly. '

CWWKC1158.cannot.lazy.enlist.beans=CWWKC1158E:You must access CDI beans prior to capturing context for the contextual action or task in order for the CDI \
beans to behave correctly when accessed from the action or task. The following CDI beans must be accessed before capturing context: {0}.
CWWKC1158.cannot.lazy.enlist.beans.explanation=When CDI context is captured, only CDI beans that have been accessed at that point in time have been created by \
the CDI runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
'When CDI context is captured, only CDI beans that have been accessed at that point in time have been created by \ the CDI runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations.'
to
'When the CDI context is captured, only CDI beans that are accessed at that point are created by the CDI runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations.'

CWWKC1158.cannot.lazy.enlist.beans.explanation=When CDI context is captured, only CDI beans that have been accessed at that point in time have been created by \
the CDI runtime. As a result, CDI beans that are first accessed in contextual operations cannot propagate their state correctly to subsequent contextual operations.
CWWKC1158.cannot.lazy.enlist.beans.useraction=The application must be changed to invoke some CDI bean operation, such as a public method, before context for \
the operation is captured.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change
'The application must be changed to invoke some CDI bean operation, such as a public method, before context for \ the operation is captured.'
to
'The application must be changed to start a CDI bean operation, such as a public method, before a context for the operation is captured.'

#
# NLS_MESSAGEFORMAT_VAR
#
# Strings in this file which contain replacement variables are processed by the MessageFormat
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

# NLS_MESSAGEFORMAT_VAR
#
# Strings in this file which contain replacement variables are processed by the MessageFormat
# class (single quote must be coded as 2 consecutive single quotes ''). Strings in this file
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

# (single quote must be coded as one single quote ').

# This message bundle does not have its own message range, and instead reserves specific error messages from the
# com.ibm.ws.concurrent.mp.1.0 message bundle
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

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

Successfully merging this pull request may close these issues.

5 participants