{"record":{"id":"8b57b373e8d5ab19","repo":"pinpoint-apm/pinpoint","slug":"connection-already-closed","errorCode":null,"errorMessage":"Connection already closed","messagePattern":"Connection already closed","errorType":"exception","errorClass":"HBaseAccessException","httpStatus":null,"severity":"error","filePath":"commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseAdminFactory.java","lineNumber":39,"sourceCode":"\nimport java.io.IOException;\nimport java.util.Objects;\n\n/**\n * @author HyunGil Jeong\n */\npublic class HbaseAdminFactory implements AdminFactory {\n\n    private final Connection connection;\n\n    public HbaseAdminFactory(Connection connection) {\n        this.connection = Objects.requireNonNull(connection, \"connection\");\n    }\n\n    @Override\n    public Admin getAdmin() {\n        if (connection.isClosed()) {\n            throw new HBaseAccessException(\"Connection already closed\");\n        }\n        try {\n            return connection.getAdmin();\n        } catch (IOException e) {\n            throw new HbaseSystemException(e);\n        }\n    }\n\n    @Override\n    public void releaseAdmin(Admin admin) {\n        if (admin == null) {\n            return;\n        }\n        try {\n            admin.close();\n        } catch (IOException e) {\n            throw new HbaseSystemException(e);\n        }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HbaseAdminFactory.java#L21-L57","documentation":"HbaseAdminFactory.getAdmin() checks the wrapped HBase Connection's isClosed() state before requesting an Admin. If the shared connection has already been closed, it throws HBaseAccessException('Connection already closed') rather than letting the client library fail with a less clear IOException deep inside connection.getAdmin().","triggerScenarios":"Calling getAdmin() after the owning HbaseConnection (or application shutdown hook) closed the underlying Connection; using a factory bean whose connection was closed due to a prior lifecycle error; retrieving an admin during/after application shutdown.","commonSituations":"Admin operations (table create/delete, namespace management) executed after Spring context closed the HBase connection bean; a component holding a stale HbaseAdminFactory reference across a reconnect/restart cycle; double-close of the connection then continued admin use.","solutions":["Ensure the connection lifecycle outlives all getAdmin() calls — close the connection only at application shutdown, after admin usage stops","Recreate/reopen the HBase Connection and rebuild the HbaseAdminFactory before calling getAdmin() again","Catch HBaseAccessException and treat it as a fatal lifecycle error rather than retrying on the same closed connection"],"exampleFix":"// before\nadmin = hbaseAdminFactory.getAdmin(); // connection already closed\n// after\nif (!connection.isClosed()) {\n    admin = hbaseAdminFactory.getAdmin();\n} else {\n    connection = connectionFactory.createConnection(conf);\n    admin = hbaseAdminFactory.getAdmin();\n}","handlingStrategy":"try-catch","validationCode":"public boolean canGetAdmin(HbaseAdminFactory factory, Connection connection) {\n    return connection != null && !connection.isClosed();\n}","typeGuard":null,"tryCatchPattern":"try {\n    Admin admin = hbaseAdminFactory.getAdmin();\n} catch (HBaseAccessException e) {\n    log.error(\"HBase connection already closed: {}\", e.getMessage());\n    // reopen connection or abort admin operation\n}","preventionTips":["Close the HBase Connection only in a shutdown hook / destroy callback that runs after all admin usage","Never cache Admin objects obtained after lifecycle events; reacquire them","Track connection state explicitly in components that survive application restarts","Guard admin operations with connection.isClosed() before calling getAdmin()"],"tags":["hbase","connection","lifecycle","closed-connection"],"backgroundTag":"connection-closed","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}