Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16494

After VetoCamelContextStartException CamelContext instance broken forever

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.7.3
    • 3.10.0
    • camel-core
    • None
    • Novice

    Description

      After camel context failed to start with VetoCamelContextStartException, it never can be started again.

      It happens because AbstractCamelContext.init() method checks vetoed is not null.  This method throw RuntimeException  (even if rethrowException = false, because called fail(vetoed)).

      Vetoed field is cleaned in method doStartContext only.

       AbstractCamelContext code:

      init(); //<--- this method throws RuntimeException when vetoed != null
      try (AutoCloseable ignored = doLifecycleChange()) {
          status = STARTING;
          LOG.trace("Starting service: {}", this);
          doStart();  //<-- this method sets vetoed == null

       

      Example for reproduce:

      import org.apache.camel.CamelContext;
      import org.apache.camel.VetoCamelContextStartException;
      import org.apache.camel.impl.DefaultCamelContext;
      import org.apache.camel.support.LifecycleStrategySupport;
      
      public class CamelContextVetoExceptionBug {
          public static void main(String[] args) {
              CamelContext context = new DefaultCamelContext();
      
              boolean[] needThrow = new boolean[]{true};
              context.addLifecycleStrategy(new LifecycleStrategySupport() {
                  @Override
                  public void onContextStarting(CamelContext context) throws VetoCamelContextStartException {
                      if (needThrow[0]) {
                          needThrow[0] = false;
                          throw new VetoCamelContextStartException("Veto onContextStarting", context, false);
                      }
                  }
              });
              context.start();
              System.out.println("Start failed without rethrow: veto=" + context.isVetoStarted());
      
      
              try {
                  context.start();
              } catch (Exception e) {
                  System.out.println("Exception: veto=" + context.isVetoStarted());
              }
          }
      } 

       

      Expected behavior:

      • next context start does not thow RuntimeException
      • next context start - started context

       
       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              akvel Valeriy Ak
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: