{"record":{"id":"e586f9e50a222582","repo":"t8y2/dbx","slug":"hive-connection-is-not-open","errorCode":null,"errorMessage":"Hive connection is not open","messagePattern":"Hive connection is not open","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/main.go","lineNumber":540,"sourceCode":"\t\t}\n\t}\n\tif database != nil {\n\t\tif err := database.Close(); err != nil {\n\t\t\tfailures = append(failures, err.Error())\n\t\t}\n\t}\n\tif len(failures) > 0 {\n\t\treturn errors.New(strings.Join(failures, \"; \"))\n\t}\n\treturn nil\n}\n\nfunc (server *server) requireConnection() (*sql.Conn, error) {\n\tserver.connectionMu.Lock()\n\tconnection := server.connection\n\tserver.connectionMu.Unlock()\n\tif connection == nil {\n\t\treturn nil, errors.New(\"Hive connection is not open\")\n\t}\n\treturn connection, nil\n}\n\nfunc (server *server) setActiveOperation(cancel context.CancelFunc) {\n\tserver.activeMu.Lock()\n\tserver.activeCancel = cancel\n\tserver.activeMu.Unlock()\n}\n\nfunc (server *server) clearActiveOperation(cancel context.CancelFunc) {\n\tcancel()\n\tserver.activeMu.Lock()\n\tserver.activeCancel = nil\n\tserver.activeMu.Unlock()\n}\n\nfunc (server *server) cancelActiveQuery() {","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/main.go#L522-L558","documentation":"requireConnection is the guard used by every Hive operation (metadata, queries, statements, cluster description). The server holds a single *sql.Conn guarded by a mutex; if no connection has been opened yet (or it was already closed by disconnect), any operation fails with this error instead of panicking on a nil connection.","triggerScenarios":"Calling hiveMetadata, validateConnection, executeQuery, executeQueryPage, executeStatements, or describeCluster before openSession established the sql.Conn, or after disconnect cleared it.","commonSituations":"Calling a query method without completing the open_session/connection handshake; the connection dropped earlier and disconnect was invoked; concurrent goroutines racing where one disconnects while another issues a query; retrying an operation after a prior failure closed the connection.","solutions":["Open a session / establish the connection (openSession or testConnection) before issuing queries","Check connection state before each operation and reconnect when the error occurs","Serialize operations so no goroutine disconnects while others are still executing queries","If the connection dropped unexpectedly, treat this as a reconnection trigger and re-run openSession with the stored connectParams"],"exampleFix":"// before\nresult, err := server.executeQuery(opts) // fails if not connected\n// after\nif _, err := server.requireConnection(); err != nil {\n    if err := server.openSession(sessionID, connectParams); err != nil { return err }\n}\nresult, err := server.executeQuery(opts)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"conn, err := server.requireConnection()\nif err != nil {\n    if err.Error() == \"Hive connection is not open\" {\n        if rerr := server.openSession(id, server.connectParams); rerr == nil {\n            conn, err = server.requireConnection()\n        }\n    }\n    if err != nil { return err }\n}","preventionTips":["Call openSession before any query/metadata operation","Guard against concurrent disconnect while queries are in flight","Treat this error as a reconnection trigger, not a fatal failure","Use testConnection/validateConnection at startup"],"tags":["connection","state","sql"],"backgroundTag":"connection-not-open","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}