{"record":{"id":"008efce645c72486","repo":"pentaho/pentaho-kettle","slug":"port-to-close-was-not-found-in-the-carte-socket-repository","errorCode":null,"errorMessage":"Port to close was not found in the Carte socket repository!","messagePattern":"Port to close was not found in the Carte socket repository!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/www/SocketRepository.java","lineNumber":131,"sourceCode":"        entry.setServerSocket( createServerSocket( port ) );\n      }\n      entry.setInUse( true );\n    }\n\n    return entry.getServerSocket();\n  }\n\n  /**\n   * We don't actually ever close a server socket, we re-use them as much as possible.\n   *\n   * @param port\n   * @throws IOException\n   */\n  public synchronized void releaseSocket( int port ) throws IOException {\n\n    SocketRepositoryEntry entry = socketMap.get( port );\n    if ( entry == null ) {\n      throw new IOException( \"Port to close was not found in the Carte socket repository!\" );\n    }\n    entry.setInUse( false );\n  }\n\n  /**\n   * @return the socketMap\n   */\n  public Map<Integer, SocketRepositoryEntry> getSocketMap() {\n    return socketMap;\n  }\n\n  /**\n   * @param socketMap\n   *          the socketMap to set\n   */\n  public void setSocketMap( Map<Integer, SocketRepositoryEntry> socketMap ) {\n    this.socketMap = socketMap;\n  }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/www/SocketRepository.java#L113-L149","documentation":"SocketRepository.releaseSocket(port) marks a previously allocated port free, but if socketMap has no entry for that port it throws IOException(\"Port to close was not found in the Carte socket repository!\"). It means code tried to release a port that was never allocated through this SocketRepository instance (or the repository was reset).","triggerScenarios":"Calling releaseSocket(port) with a port outside the repository's allocated range, releasing twice for the same allocation after the entry was removed, or releasing on a different Carte SocketRepository instance than the one that allocated the port.","commonSituations":"Custom transformation code closing sockets in a finally block that runs even when allocation failed; cleanup logic in clustered transformations running on the wrong slave node; bookkeeping mismatch after Carte re-created its socket map (restart) while clients still hold old port numbers.","solutions":["Only release ports that were successfully allocated via the same SocketRepository; guard the release call with the allocation result.","Make release idempotent: check the entry/port exists before releasing instead of treating absence as an error.","Trace which port number is being released; ensure the clustered transformation's slave server config matches the one that allocated it.","If caused by a double-release in cleanup code, add a flag so the release runs once."],"exampleFix":"// before: releases even when allocation failed\nint port = socketRepository.allocateServerSocketPort(...);\n... // if allocation threw, finally still runs\nfinally { socketRepository.releaseSocket(port); }\n\n// after: only release what was allocated\nint port = -1;\ntry {\n  port = socketRepository.allocateServerSocketPort(...);\n  ...\n} finally {\n  if (port >= 0) socketRepository.releaseSocket(port);\n}","handlingStrategy":"validation","validationCode":"if (port >= 0 && socketWasAllocated(port)) {\n  socketRepository.releaseSocket(port);\n}","typeGuard":null,"tryCatchPattern":"try {\n  socketRepository.releaseSocket(port);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"not found\")) {\n    log.debug(\"Port {} already released or never allocated; ignoring\", port); // make cleanup idempotent\n  } else throw e;\n}","preventionTips":["Release only ports obtained from a successful allocation, on the same SocketRepository.","Make cleanup code idempotent so double releases are harmless.","Log allocated/released ports in clustered runs to spot bookkeeping mismatches."],"tags":["network","port","carte","socket","cleanup"],"backgroundTag":"resource-not-found","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"}