{"record":{"id":"98f3fdd0c81a701e","repo":"quarkusio/quarkus","slug":"cannot-create-a-runningdevservicesdatasource-befor","errorCode":null,"errorMessage":"Cannot create a RunningDevServicesDatasource before the H2 datasource has been started.","messagePattern":"Cannot create a RunningDevServicesDatasource before the H2 datasource has been started\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java","lineNumber":139,"sourceCode":"                                                + tcpServer.getStatus());\n                            }\n                        }\n\n                        @Override\n                        public String getConnectionInfo() {\n                            return getEffectiveJdbcUrl();\n                        }\n\n                        @Override\n                        public String getContainerId() {\n                            return null;\n                        }\n\n                        @Override\n                        public DevServicesDatasourceProvider.RunningDevServicesDatasource runningDevServicesDatasource() {\n                            // Override, so we can check the connection url instead of the container id\n                            if (connectionUrl == null) {\n                                throw new IllegalStateException(\n                                        \"Cannot create a RunningDevServicesDatasource before the H2 datasource has been started.\");\n                            }\n                            // It would be nice to cache this, but since this is an interface, it can't be done at this level, and would have to be done by every implementing class\n                            return new DevServicesDatasourceProvider.RunningDevServicesDatasource(getContainerId(),\n                                    getEffectiveJdbcUrl(),\n                                    getReactiveUrl(), getUsername(), getPassword());\n                        }\n\n                    };\n                } catch (SQLException throwables) {\n                    throw new RuntimeException(throwables);\n                }\n            }\n\n            @Override\n            public Optional<DevServicesDatasourceProvider.RunningDevServicesDatasource> findRunningComposeDatasource(\n                    LaunchMode launchMode, boolean useSharedNetwork, DevServicesDatasourceContainerConfig containerConfig,\n                    DevServicesComposeProjectBuildItem composeProjectBuildItem) {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java#L121-L157","documentation":"H2 Dev Services creates a RunningDevServicesDatasource lazily via an anonymous DevServicesDatasourceProvider. This error means the provider's runningDevServicesDatasource() accessor was called before start() had produced an H2 file JDBC connection URL, so connectionUrl is still null. Unlike container-based providers, H2 runs in-process, so there is no container ID to query — the URL is the only start indicator.","triggerScenarios":"Calling runningDevServicesDatasource() on the H2 DevServicesDatasourceProvider before the start() method has completed and set connectionUrl; or when start() did not run / returned no URL (e.g. dev services disabled, inline datasource already configured).","commonSituations":"Custom build steps or dev-mode tooling consuming the DevServicesDatasourceProvider during augmentation before DevServicesProcessor start phases ran; tests or recorders probing the datasource URL too early; disabling quarkus.datasource.devservices.enabled but still querying the provider.","solutions":["Ensure start() on the H2 provider is invoked (via DevServicesProcessor build steps) before calling runningDevServicesDatasource()","Check that quarkus.datasource.devservices.enabled is not set to false while code still expects a started datasource","Consume the DevServicesResultBuildItem produced by DevServicesProcessor instead of poking the provider directly","If the datasource should never be started by dev services, avoid the provider entirely and build the JDBC URL from quarkus.datasource.jdbc.url"],"exampleFix":"// before\nvar running = h2Provider.runningDevServicesDatasource(); // throws before start\n// after\nvar result = h2Provider.start(launchConfig, devServicesConfig); // sets connectionUrl\nvar running = h2Provider.runningDevServicesDatasource();","handlingStrategy":"validation","validationCode":"if (provider instanceof H2DevServicesProviderCapture) {\n    // only call after DevServicesProcessor produced the datasource start result\n    var result = devServicesResultBuildItem; // from DevServicesProcessor build step\n    if (result == null || result.getConnectionInfo() == null) {\n        throw new IllegalStateException(\"H2 dev services not started yet\");\n    }\n}\nvar running = provider.runningDevServicesDatasource();","typeGuard":"boolean isH2DevServicesStarted(DevServicesDatasourceProvider p) {\n    try { p.runningDevServicesDatasource(); return true; }\n    catch (IllegalStateException e) { return false; }\n}","tryCatchPattern":"try {\n    var running = provider.runningDevServicesDatasource();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"before the H2 datasource has been started\")) {\n        // fall back: compute URL from config or defer until after start()\n    } else throw e;\n}","preventionTips":["Only consume the provider after the DevServicesProcessor build steps have run","Rely on DevServicesResultBuildItem instead of calling provider accessors directly","Verify devservices are enabled before expecting a started datasource"],"tags":["devservices","h2","datasource","lifecycle"],"backgroundTag":"devservices-not-started","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}