{"record":{"id":"eda0480369107efd","repo":"pentaho/pentaho-kettle","slug":"jobgetmailsfrompop-error-closingconnection","errorCode":null,"errorMessage":"JobGetMailsFromPOP.Error.ClosingConnection","messagePattern":"JobGetMailsFromPOP\\.Error\\.ClosingConnection","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"warning","filePath":"plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java","lineNumber":871,"sourceCode":"      // close the folder, passing in a true value to expunge the deleted message\n      closeFolder( expunge );\n      clearFilters();\n      if ( this.store != null ) {\n        this.store.close();\n        this.store = null;\n      }\n      if ( this.session != null ) {\n        this.session = null;\n      }\n      if ( this.destinationIMAPFolder != null ) {\n        this.destinationIMAPFolder.close( expunge );\n      }\n\n      if ( log.isDebug() ) {\n        log.logDebug( BaseMessages.getString( PKG, \"MailConnection.ConnectionClosed\" ) );\n      }\n    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG, \"JobGetMailsFromPOP.Error.ClosingConnection\" ), e );\n    }\n  }\n\n  /**\n   * Export message content to a filename.\n   *\n   * @param filename\n   *          the target filename\n   * @param foldername\n   *          the parent folder of filename\n   * @throws KettleException\n   */\n\n  public void saveMessageContentToFile( String filename, String foldername ) throws KettleException {\n    OutputStream os = null;\n    try {\n      os = KettleVFS.getInstance( bowl )\n        .getOutputStream( foldername + ( foldername.endsWith( \"/\" ) ? \"\" : \"/\" ) + filename, false );","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java#L853-L889","documentation":"disconnect() wraps exceptions raised while closing the folder and store (its internal cleanup steps) into a KettleException with JobGetMailsFromPOP.Error.ClosingConnection. It means the session could not be shut down cleanly — usually because the server already dropped the connection.","triggerScenarios":"disconnect() calls closeFolder()/store.close() and any of them throws: socket already closed, session timed out, SSL channel broken.","commonSituations":"Server-side idle timeouts (e.g. 30 min IMAP logout), network drop between connect and disconnect, exception in job flow skipping normal close then disconnect failing again.","solutions":["Inspect the chained cause — typically a socket/ConnectionException meaning the server already closed; safe to treat as cleanup warning.","Ensure disconnect() is called in a finally block exactly once after the job step completes.","Enable IMAP keepalive or shorten job duration to stay under the server idle timeout.","If it recurs, log-and-continue on disconnect failures since resources are usually released server-side anyway."],"exampleFix":"// before\ndisconnect(); // throws if server already dropped\n// after\ntry {\n  disconnect();\n} catch (KettleException e) {\n  log.logBasic(\"Connection already closed by server: \" + e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// only disconnect once, after confirming state\nif (mailConnection != null && mailConnection.getStore() != null && mailConnection.getStore().isConnected()) {\n  mailConnection.disconnect();\n}","typeGuard":null,"tryCatchPattern":"try {\n  mailConnection.disconnect();\n} catch (KettleException e) {\n  log.logBasic(\"Disconnect failed, server likely already closed: \" + e.getCause().getMessage());\n}","preventionTips":["Call disconnect in a finally block once per connection","Treat disconnect failures as warnings unless resources must be freed server-side","Shorten job duration to avoid idle timeouts","Log at basic level for cleanup failures"],"tags":["javamail","disconnect","session-timeout","kettle","email"],"backgroundTag":"broken-pipe","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"}