apache/dubbo · error · IllegalStateException

Not all application models are completely destroyed, remaini

Error message

Not all application models are completely destroyed, remaining <remainApplications.size()> application models may be created during destruction: <remainApplications>

What it means

Thrown by FrameworkModel.checkApplicationDestroy during framework destruction when one or more ApplicationModels still exist. A FrameworkModel can only finish destroying its global resources when all child ApplicationModels are gone; leftover applications (sometimes created mid-teardown) abort the process.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java:158

            }

            // remove from allInstances and reset default FrameworkModel
            synchronized (globalLock) {
                allInstances.remove(this);
                resetDefaultFrameworkModel();
            }

            // if all FrameworkModels are destroyed, clean global static resources, shutdown dubbo completely
            destroyGlobalResources();
        }
    }

    private void checkApplicationDestroy() {
        synchronized (instLock) {
            if (applicationModels.size() > 0) {
                List<String> remainApplications =
                        applicationModels.stream().map(ScopeModel::getDesc).collect(Collectors.toList());
                throw new IllegalStateException(
                        "Not all application models are completely destroyed, remaining " + remainApplications.size()
                                + " application models may be created during destruction: " + remainApplications);
            }
        }
    }

    private void destroyGlobalResources() {
        synchronized (globalLock) {
            if (allInstances.isEmpty()) {
                GlobalResourcesRepository.getInstance().destroy();
            }
        }
    }

    /**
     * During destroying the default FrameworkModel, the FrameworkModel.defaultModel() or ApplicationModel.defaultModel()
     * will return a broken model, maybe cause unpredictable problem.
     * Recommendation: Avoid using the default model as much as possible.

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Destroy all ApplicationModels before destroying the FrameworkModel; respect the teardown order.
  2. Stop/quiesce any background tasks that may lazily create ApplicationModels before starting shutdown.
  3. In tests, use Dubbo's test utilities to fully reset models and avoid leaking applications across cases.
  4. Audit static singletons or auto-initializers that can create an ApplicationModel during destruction.

Example fix

// before
frameworkModel.destroy(); // applicationModels not yet cleared -> throws

// after
for (ApplicationModel app : frameworkModel.getApplicationModels()) {
    app.destroy();
}
frameworkModel.destroy();
Defensive patterns

Strategy: validation

Validate before calling

// Ensure all application models are gone before destroying the framework
List<ApplicationModel> remaining = new ArrayList<>(frameworkModel.getApplicationModels());
for (ApplicationModel app : remaining) {
    if (!app.isDestroyed()) app.destroy();
}
if (!frameworkModel.getApplicationModels().isEmpty()) {
    throw new IllegalStateException(
        "Cannot destroy FrameworkModel: "
            + frameworkModel.getApplicationModels() + " still present");
}
frameworkModel.destroy();

Try / catch

try {
    frameworkModel.destroy();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Not all application models are completely destroyed")) {
        // explicitly destroy leftover ApplicationModels first, then retry
    }
    throw e;
}

Prevention

When it happens

Trigger: FrameworkModel destroy sequence runs checkApplicationDestroy() and finds applicationModels.size() > 0. Happens when an ApplicationModel is created during the destruction window or was never properly destroyed first.

Common situations: An async task or lazy initializer spins up a new ApplicationModel while the framework is shutting down. Misordered shutdown where the FrameworkModel is destroyed before all its ApplicationModels. Static/singleton code that auto-creates an application on access during teardown. Test frameworks that leak application models across tests.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/7a48118731e895f6. Report an issue: GitHub.