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


##########
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:
   Ah! yes, you are right; I was too focused on inter-thread interaction that 
it slipped my mind that even within the same thread, this could be called by 
another part of the code which will result in context loss
   
   Let me add
   ```
   Map<String, String> currentMdc = MDC.getCopyOfContextMap();
         if (currentMdc != null) {
           contextMap.putAll(currentMdc); // Preserve existing
         }
   ```
   in the top of `setContextFromAsync` to save the MDC already present
   



-- 
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