{"record":{"id":"dcfbda277c47f390","repo":"pentaho/pentaho-kettle","slug":"repository-is-already-connected","errorCode":null,"errorMessage":"Repository is already connected!","messagePattern":"Repository is already connected!","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryConnectionDelegate.java","lineNumber":139,"sourceCode":"\n    this.majorVersion = REQUIRED_MAJOR_VERSION;\n    this.minorVersion = REQUIRED_MINOR_VERSION;\n  }\n\n  /**\n   * Connect to the repository\n   */\n  public synchronized void connect() throws KettleException {\n    connect( false, false );\n  }\n\n  public synchronized void connect( boolean no_lookup ) throws KettleException {\n    connect( no_lookup, false );\n  }\n\n  public synchronized void connect( boolean no_lookup, boolean ignoreVersion ) throws KettleException {\n    if ( repository.isConnected() ) {\n      throw new KettleException( \"Repository is already connected!\" );\n    }\n    try {\n      database.initializeVariablesFrom( null );\n      database.connect();\n      if ( !ignoreVersion ) {\n        verifyVersion();\n      }\n      setAutoCommit( false );\n      repository.setConnected( true );\n      /*\n       * Done lazily now.\n       *\n       * if (!no_lookup) { try { repository.connectionDelegate.setLookupStepAttribute();\n       * repository.connectionDelegate.setLookupTransAttribute();\n       * repository.connectionDelegate.setLookupJobEntryAttribute();\n       * repository.connectionDelegate.setLookupJobAttribute(); } catch (KettleException dbe) { throw new\n       * KettleException(\"Error setting lookup prep.statements\", dbe); } }\n       */","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryConnectionDelegate.java#L121-L157","documentation":"KettleException thrown by KettleDatabaseRepositoryConnectionDelegate.connect when connect() is called while the repository already reports isConnected(). This is a state guard against double-connecting the same underlying Database object. It prevents resource leaks and re-initialization of an active connection.","triggerScenarios":"Calling repository.connect() (or delegate.connect) twice without disconnect() in between, e.g., in plugin code that assumes a fresh connection each time while the repository singleton is already connected.","commonSituations":"Long-lived repository shared across threads where one component connects and another reconnects; retry logic that doesn't check isConnected() first.","solutions":["Check repository.isConnected() before calling connect()","Call repository.disconnect() before reconnecting","Share the existing connection instead of reconnecting","Synchronize connect/disconnect calls if multiple threads manage the lifecycle"],"exampleFix":"// before\nrepository.connect(\"admin\", \"admin\"); // throws if already connected\n\n// after\nif (!repository.isConnected()) {\n  repository.connect(\"admin\", \"admin\");\n}","handlingStrategy":"validation","validationCode":"if (repository.isConnected()) { return; } // skip connect when already up\nrepository.connect(user, pass);","typeGuard":"boolean canConnect = !repository.isConnected();","tryCatchPattern":"try { if (!repository.isConnected()) repository.connect(u, p); } catch (KettleException e) { throw new RuntimeException(\"Repository connect failed\", e); }","preventionTips":["Always check isConnected() before connect()","Centralize repository connection in a singleton/provider","Pair every connect() with a disconnect() in finally blocks","Avoid reconnect logic in retry loops without a state check"],"tags":["repository","connection","state"],"backgroundTag":"address-already-in-use","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}