mayur mohan created CAMEL-24516:
-----------------------------------

             Summary: AbstractCamelContext: keep TypeConverter non-null after 
stop; reset only on restart
                 Key: CAMEL-24516
                 URL: https://issues.apache.org/jira/browse/CAMEL-24516
             Project: Camel
          Issue Type: Bug
            Reporter: mayur mohan


h2. Problem

{{AbstractCamelContext.forceStopLazyInitialization()}} sets {{typeConverter}}, 
{{typeConverterRegistry}} and {{injector}} to {{null}} at the tail of 
{{doStop()}}. Any async work still running on the reactive executor at that 
point (e.g. a Multicast continuation, parallel Splitter task, or Quartz SFTP 
poll) hits a bare {{NullPointerException}} at one of the ~200 unguarded 
{{getTypeConverter()}} call sites across {{core/}}.

{{DefaultReactiveExecutor.doStop()}} does no draining, so async continuations 
are not guaranteed to have finished when the tail of {{doStop()}} runs -- even 
when graceful route shutdown reports success.

h2. Root Cause

{{AbstractCamelContext.forceStopLazyInitialization()}} 
({{core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java}}):

{code:java}
protected void forceStopLazyInitialization() {
    camelContextExtension.resetInjector();
    camelContextExtension.resetTypeConverterRegistry();
    camelContextExtension.resetTypeConverter(); // sets field to null
}
{code}

h2. Fix

Move the three null-and-recreate calls from {{forceStopLazyInitialization()}} 
to the start of {{forceLazyInitialization()}}, guarded by {{firstStartDone}}. 
The fields are nulled synchronously at the beginning of the next {{doStart()}} 
instead of at the end of {{doStop()}}:

- {{getTypeConverter()}} is never {{null}} during the stopped/idle window
- All ~200 unguarded call sites fixed at once with no null-checks or sentinels
- Restart-in-place ({{stop()}}/{{start()}} on the same instance) preserved

h2. Related

Supersedes CAMEL-24510 and CAMEL-24515 which attempted per-call-site fixes.

h2. PR

https://github.com/apache/camel/pull/25775



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to