{"record":{"id":"2de5b779579b245d","repo":"t8y2/dbx","slug":"close-hive-agent-sessions-s-2de5b7","errorCode":null,"errorMessage":"close Hive Agent sessions: %s","messagePattern":"close Hive Agent sessions: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agents/drivers/hive-go/main.go","lineNumber":310,"sourceCode":"\treturn session.server.disconnect()\n}\n\nfunc (runtimeServer *runtimeServer) closeAllSessions() error {\n\truntimeServer.mu.Lock()\n\tsessions := runtimeServer.sessions\n\truntimeServer.sessions = map[string]*agentSession{}\n\truntimeServer.mu.Unlock()\n\tvar failures []string\n\tfor id, session := range sessions {\n\t\tsession.mu.Lock()\n\t\terr := session.server.disconnect()\n\t\tsession.mu.Unlock()\n\t\tif err != nil {\n\t\t\tfailures = append(failures, fmt.Sprintf(\"%s: %v\", id, err))\n\t\t}\n\t}\n\tif len(failures) > 0 {\n\t\treturn fmt.Errorf(\"close Hive Agent sessions: %s\", strings.Join(failures, \"; \"))\n\t}\n\treturn nil\n}\n\nfunc newServer(params connectParams) (*server, error) {\n\tconfig, err := parseConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tserver := &server{\n\t\tparams:        params,\n\t\tconfig:        config,\n\t\tquerySessions: map[string]*querySession{},\n\t}\n\tif err := server.openConnection(); err != nil {\n\t\treturn nil, err\n\t}\n\treturn server, nil","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/main.go#L292-L328","documentation":"This error aggregates every per-session disconnect failure encountered while the Hive Agent runtime is shutting down. closeAllSessions iterates all live agent sessions, calls server.disconnect() on each, and collects any failures as \"<sessionID>: <err>\" strings. It then joins them with \"; \" so a single error reports all sessions that failed to close cleanly, rather than only the first.","triggerScenarios":"Raised when the agent shuts down (shutdown RPC or process teardown via dispatch/closeAllSessions) and one or more underlying Hive/go hive connections fail to close — e.g. a broken network connection to HiveServer2, a session already terminated server-side, or a driver-level close timeout.","commonSituations":"Long-lived sessions whose HiveServer2 connection expired or was dropped by a firewall/load balancer idle timeout; killing the agent while queries are still streaming; HiveServer2 restarts that orphaned the client sessions.","solutions":["Inspect the per-session detail after 'close Hive Agent sessions:' to find which session and underlying cause failed","Verify the HiveServer2 endpoint is reachable and sessions have not been expired server-side (hive.server2.session.close timeout)","Treat this as a shutdown-time warning in most cases — sessions are being discarded anyway; re-check cleanup logic only if resources leak","Retry the disconnect or ensure idle keepalives are configured so connections are not stale at shutdown"],"exampleFix":"// before: ignoring close errors can mask root causes\n_ = runtimeServer.closeAllSessions()\n// after: log the aggregated failure detail\nif err := runtimeServer.closeAllSessions(); err != nil {\n    log.Printf(\"shutdown: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"if err := runtimeServer.closeAllSessions(); err != nil { log.Printf(\"session close failures: %v\", err) }","typeGuard":null,"tryCatchPattern":"if err := closeAllSessions(); err != nil {\n    for _, part := range strings.Split(strings.TrimPrefix(err.Error(), \"close Hive Agent sessions: \"), \"; \") {\n        log.Println(\"session close failure:\", part)\n    }\n}","preventionTips":["Configure TCP keepalives / HiveServer2 session timeouts so connections stay valid","Close sessions proactively when work completes instead of relying on shutdown","Log disconnect errors per session during operation, not only at teardown"],"tags":["go","hive","session-cleanup","shutdown"],"backgroundTag":"session-close-failure","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"}