{"record":{"id":"d7c7296937b40712","repo":"alibaba/druid","slug":"interrupt","errorCode":null,"errorMessage":"interrupt","messagePattern":"interrupt","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java","lineNumber":671,"sourceCode":"            }\n        }\n\n        this.connectProperties = properties;\n    }\n\n    public void init() throws SQLException {\n        if (inited) {\n            return;\n        }\n\n        // bug fixed for dead lock, for issue #2980\n        DruidDriver.getInstance();\n\n        final ReentrantLock lock = this.lock;\n        try {\n            lock.lockInterruptibly();\n        } catch (InterruptedException e) {\n            throw new SQLException(\"interrupt\", e);\n        }\n\n        boolean init = false;\n        try {\n            if (inited) {\n                return;\n            }\n\n            initStackTrace = Utils.toString(Thread.currentThread().getStackTrace());\n\n            this.id = DruidDriver.createDataSourceId();\n            if (this.id > 1) {\n                long delta = (this.id - 1) * 100000;\n                connectionIdSeedUpdater.addAndGet(this, delta);\n                statementIdSeedUpdater.addAndGet(this, delta);\n                resultSetIdSeedUpdater.addAndGet(this, delta);\n                transactionIdSeedUpdater.addAndGet(this, delta);\n            }","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java#L653-L689","documentation":"SQLException('interrupt') wrapping InterruptedException, thrown by init() when the thread waiting to acquire the init lock (lock.lockInterruptibly()) is interrupted before it obtains the lock. Druid prefers to surface the interruption as a checked SQLException rather than reset the interrupt flag silently.","triggerScenarios":"Thread calling dataSource.init() (or the first getConnection() that triggers lazy init) is interrupted via Thread.interrupt() while blocked on this.lock.lockInterruptibly() at line 665. The catch at 669 wraps and throws.","commonSituations":"Application shutdown interrupting threads mid-startup; a thread pool / executor shutting down tasks during datasource init; a watchdog or timeout framework interrupting the init thread; reusing interrupted threads.","solutions":["Ensure the thread performing init()/first getConnection() is not interrupted during startup; defer shutdown signals until init completes.","If interruption is expected (e.g. bounded startup), catch SQLException and check getCause() instanceof InterruptedException, then retry init on a non-interrupted thread.","Call init() eagerly during a controlled startup phase rather than lazily on the request path."],"exampleFix":"// before\nexecutor.submit(() -> dataSource.init()).get(2, TimeUnit.SECONDS); // may interrupt\n// after\nThread t = new Thread(() -> { try { dataSource.init(); } catch (SQLException e) { /* log */ } });\nt.start();\nt.join(); // do not interrupt during init","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) {\n    Thread.interrupted(); // clear flag\n    LOG.warn(\"init thread was interrupted; clearing and proceeding\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    dataSource.init();\n} catch (SQLException e) {\n    if (\"interrupt\".equals(e.getMessage()) && e.getCause() instanceof InterruptedException) {\n        // re-run init on a fresh, non-interrupted thread\n        throw new IllegalStateException(\"datasource init interrupted\", e);\n    }\n    throw e;\n}","preventionTips":["Do not run init()/first getConnection() on threads that may be interrupted (shutdown hooks, timed tasks).","Initialize the pool eagerly in a controlled startup phase.","Keep shutdown signals from racing startup."],"tags":["lifecycle","threading","interrupt","init"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}