{"record":{"id":"d8bb05828697fd4a","repo":"argoproj/argo-workflows","slug":"failed-to-create-upper-db-session-w","errorCode":null,"errorMessage":"failed to create upper/db session: %w","messagePattern":"failed to create upper/db session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/sqldb/sqldb.go","lineNumber":306,"sourceCode":"\t}\n\n\t// Wrap the MySQL connector so Connect (dial + handshake read) is bounded by\n\t// connectTimeout, protecting against a half-open server the same way lib/pq's\n\t// connect_timeout protects PostgreSQL.\n\tconnector, err := mysql.NewConnector(mysqlCfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create mysql connector: %w\", err)\n\t}\n\twrapped := &timeoutConnector{Connector: connector, timeout: connectTimeout}\n\n\t// Create traced *sql.DB using otelsql\n\tsqlDB := otelsql.OpenDB(wrapped, otelSQLOptions(semconv.DBSystemNameMySQL, cfg.Database)...)\n\n\t// Wrap with upper/db\n\tsession, err := mysqladp.New(sqlDB)\n\tif err != nil {\n\t\tsqlDB.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create upper/db session: %w\", err)\n\t}\n\n\tsession = ConfigureDBSession(session, persistPool)\n\n\t// this is needed to make MySQL run in a Golang-compatible UTF-8 character set.\n\t_, err = session.SQL().Exec(\"SET NAMES 'utf8mb4'\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t_, err = session.SQL().Exec(\"SET CHARACTER SET utf8mb4\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn session, nil\n}\n\n// otelSQLOptions returns the common otelsql tracing options for a database connection.\nfunc otelSQLOptions(systemName attribute.KeyValue, database string) []otelsql.Option {","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/util/sqldb/sqldb.go#L288-L324","documentation":"Returned when upper/db's MySQL adapter (mysqladp.New) fails to wrap the already-opened *sql.DB into an upper/db session. The traced *sql.DB is closed before returning so connections are not leaked. This is a session-construction failure in the upper/db layer, not a TCP dial failure — the underlying *sql.DB was created successfully.","triggerScenarios":"createMySQLDBSessionWithCreds passes a valid *sql.DB to mysqladp.New, and upper/db rejects it (unexpected nil DB or adapter initialization error). Rare in practice since a non-nil *sql.DB from otelsql.OpenDB should always be acceptable.","commonSituations":"Version incompatibility between the vendored upper/db adapter and database/sql plumbing; nil deref from passing a nil *sql.DB in custom code paths; patched dependency builds.","solutions":["Read the wrapped error from upper/db's mysql adapter; check for nil sql.DB input in the calling path.","Check the vendored upper/db versions (github.com/uptrace/updb / upper/db v4 adapter) for known incompatibilities and run make codegen/vendor update.","Retry controller startup — if this persists on a stock build, file an issue with the wrapped error text.","As a diagnostic, connect with the same DSN via a plain sql.Open to separate upper/db issues from driver issues."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the *sql.DB is usable before upper/db wrap\nif sqlDB == nil { return errors.New(\"nil sql.DB for mysql session\") }\nif err := sqlDB.Ping(); err != nil { return fmt.Errorf(\"mysql unreachable: %w\", err) }","typeGuard":null,"tryCatchPattern":"session, err := CreateDBSessionWithCreds(ctx)\nif err != nil && strings.Contains(err.Error(), \"failed to create upper/db session\") {\n    logger.Error(ctx, \"upper/db mysql adapter failed\", err)\n    return err\n}","preventionTips":["Keep vendored upper/db versions aligned with the argo-workflows release.","Ping the DB early in startup to separate network vs adapter failures.","Never pass a nil *sql.DB into session construction paths."],"tags":["database","mysql","upperdb","session"],"backgroundTag":"db-session-init-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}