t8y2/dbx · error

Hive connection is not open

Error message

Hive connection is not open

What it means

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.

Source

Thrown at agents/drivers/argo-go/main.go:540

		}
	}
	if database != nil {
		if err := database.Close(); err != nil {
			failures = append(failures, err.Error())
		}
	}
	if len(failures) > 0 {
		return errors.New(strings.Join(failures, "; "))
	}
	return nil
}

func (server *server) requireConnection() (*sql.Conn, error) {
	server.connectionMu.Lock()
	connection := server.connection
	server.connectionMu.Unlock()
	if connection == nil {
		return nil, errors.New("Hive connection is not open")
	}
	return connection, nil
}

func (server *server) setActiveOperation(cancel context.CancelFunc) {
	server.activeMu.Lock()
	server.activeCancel = cancel
	server.activeMu.Unlock()
}

func (server *server) clearActiveOperation(cancel context.CancelFunc) {
	cancel()
	server.activeMu.Lock()
	server.activeCancel = nil
	server.activeMu.Unlock()
}

func (server *server) cancelActiveQuery() {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Open a session / establish the connection (openSession or testConnection) before issuing queries
  2. Check connection state before each operation and reconnect when the error occurs
  3. Serialize operations so no goroutine disconnects while others are still executing queries
  4. If the connection dropped unexpectedly, treat this as a reconnection trigger and re-run openSession with the stored connectParams

Example fix

// before
result, err := server.executeQuery(opts) // fails if not connected
// after
if _, err := server.requireConnection(); err != nil {
    if err := server.openSession(sessionID, connectParams); err != nil { return err }
}
result, err := server.executeQuery(opts)
Defensive patterns

Strategy: try-catch

Try / catch

conn, err := server.requireConnection()
if err != nil {
    if err.Error() == "Hive connection is not open" {
        if rerr := server.openSession(id, server.connectParams); rerr == nil {
            conn, err = server.requireConnection()
        }
    }
    if err != nil { return err }
}

Prevention

When it happens

Trigger: Calling hiveMetadata, validateConnection, executeQuery, executeQueryPage, executeStatements, or describeCluster before openSession established the sql.Conn, or after disconnect cleared it.

Common situations: 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.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/e586f9e50a222582. Report an issue: GitHub.