{"record":{"id":"fc803d065f2f6e38","repo":"t8y2/dbx","slug":"failed-to-restore-oracle-segment-attributes-w","errorCode":null,"errorMessage":"failed to restore Oracle segment attributes: %w","messagePattern":"failed to restore Oracle segment attributes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agents/drivers/oracle-go/main.go","lineNumber":3148,"sourceCode":"\t\treturn s.appendTableDependentDDL(schema, table, fallback), nil\n\t}\n\treturn \"\", err\n}\n\nfunc withOraclePortableMetadataSession(db *sql.DB, operation func(*sql.Conn) error) (err error) {\n\tconn, err := db.Conn(context.Background())\n\tif err != nil {\n\t\treturn err\n\t}\n\tif _, err = conn.ExecContext(context.Background(), oracleDisableSegmentAttributesSQL); err != nil {\n\t\t_ = conn.Close()\n\t\treturn fmt.Errorf(\"failed to disable Oracle segment attributes: %w\", err)\n\t}\n\tdefer func() {\n\t\tif _, resetErr := conn.ExecContext(context.Background(), oracleEnableSegmentAttributesSQL); resetErr != nil {\n\t\t\t_ = conn.Raw(func(any) error { return driver.ErrBadConn })\n\t\t\tif err == nil {\n\t\t\t\terr = fmt.Errorf(\"failed to restore Oracle segment attributes: %w\", resetErr)\n\t\t\t}\n\t\t}\n\t\t_ = conn.Close()\n\t}()\n\treturn operation(conn)\n}\n\nfunc (s *server) appendTableDependentDDL(schema, table, tableDDL string) string {\n\tindexDDLs, _ := s.loadTableIndexDDLs(schema, table)\n\treturn s.appendTableDependentDDLWithIndexes(schema, table, tableDDL, indexDDLs)\n}\n\nfunc (s *server) appendTableDependentDDLWithIndexes(schema, table, tableDDL string, indexDDLs []string) string {\n\tvar builder strings.Builder\n\tbaseDDL := strings.TrimSpace(tableDDL)\n\tbuilder.WriteString(baseDDL)\n\tdependentAppended := false\n\tappendDependent := func(ddl string) {","sourceCodeStart":3130,"sourceCodeEnd":3166,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/oracle-go/main.go#L3130-L3166","documentation":"This is the deferred cleanup path of the segment-attributes helper: after the operation runs, the driver re-enables Oracle segment attributes. If that restore statement fails, the driver marks the connection bad (driver.ErrBadConn) and, when the main operation did not already fail, returns 'failed to restore Oracle segment attributes'. The Oracle session may be left with segment attributes disabled.","triggerScenarios":"Connection dropped or session killed between the operation and the deferred reset; privileges changed mid-flight; the enable SQL fails for version/edition reasons even though the disable succeeded.","commonSituations":"Long operations whose connection times out before cleanup; network interruption during a large export; DBA killing the session; failover to a node where the session state is gone.","solutions":["Reconnect and manually run the enable-segment-attributes SQL to restore session state","Retry the whole operation; the driver invalidates the bad connection so a retry gets a fresh one","Investigate the wrapped reset error (check ORA- code) — typically a dropped connection","Shorten operation duration or raise Oracle/network idle timeouts so the conn survives to cleanup"],"exampleFix":"// before\nconn.ExecContext(ctx, oracleDisableSegmentAttributesSQL) // long op, conn dies before reset\n// after\nctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) // keep-alive long enough for op + reset\ndefer cancel()","handlingStrategy":"try-catch","validationCode":"if err := db.PingContext(ctx); err != nil { return err } // conn health before long operation","typeGuard":null,"tryCatchPattern":"err := withSegmentAttributesDisabled(db, op)\nif err != nil && strings.Contains(err.Error(), \"restore Oracle segment attributes\") {\n    // reconnect and manually re-enable attributes before proceeding\n    if rdb, e2 := sql.Open(\"oracle\", dsn); e2 == nil {\n        rdb.ExecContext(ctx, oracleEnableSegmentAttributesSQL)\n        rdb.Close()\n    }\n}","preventionTips":["Ensure the operation duration fits within connection lifetime/idle timeouts","Enable TCP keepalives on the Oracle connection to survive NAT/firewall drops","After this error, always manually re-run the enable SQL to restore session state","Rely on the driver's ErrBadConn invalidation and retry the operation once"],"tags":["go","oracle","cleanup","stale-connection"],"backgroundTag":"connection-reset-during-cleanup","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"}