wmedvede commented on code in PR #4094:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4094#discussion_r2588069484


##########
jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java:
##########
@@ -225,9 +226,35 @@ protected void reconnect() {
         }
         
getProcessRuntime().getProcessInstanceManager().setLock(((MutableProcessInstances<T>)
 process.instances()).lock());
         processInstance.setMetaData(KOGITO_PROCESS_INSTANCE, this);
+
+        restoreProcessInstanceContext();
+
         processInstance.reconnect();
     }
 
+    private void restoreProcessInstanceContext() {
+        Map<String, List<String>> headers = processInstance.getHeaders();
+        if (headers != null && !headers.isEmpty()) {
+            Map<String, String> contextMap = 
convertHeadersToContextMap(headers);
+            if (!contextMap.isEmpty()) {
+                
org.kie.kogito.services.context.ProcessInstanceContext.setContextFromAsync(contextMap);

Review Comment:
   Above I pointed out let's say one execution pat, but I was referring to the 
invocation of MDC.setContextMap(theNewValues);  in general. 
   
   When we do this invocaton, whatever value in the MDC context is cleared, and 
now, it has theNewValues.
   But, how do we know if the caller Thread has values stored in the MDC 
context, imagine IDK, kogitoTransactionID=1234 that we shouldn't clear?
   
   Something like this:
   1-) In the caller Thread, the execution flow produces this:
        A "kogito" method starts (or any other api)
        MDC.put("kogitoTransactionID", "1234")  //for whatever reason, 
eventually another API in the middle.
   2-) Now, the execution flow, reaches this invocation: (for whatever reason)
        ProcessInstanceContext.setContextFromAsync(theNewValues).     
   3-) Now the "kogito" medhod continues
        The method expects that "kogitoTransactionID"="1234"  is still in the 
MDC context, but this value was cleared as a side effect of the invocation in 2)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to