dgraph-io/dgraph · error

while upgrading cors

Error message

while upgrading cors

What it means

OfflineUpgradeFrom2011To2103 wraps any fixCors failure with this message. It means the CORS/GraphQL-schema fix portion of the 20.11 -> 21.03 offline upgrade failed; the wrapped chain includes the updateGQLSchemaOffline or dropDepreciated error.

Source

Thrown at upgrade/change_v21.03.0.go:443

		return err
	}
	entry = &badger.Entry{}
	entry.Key = x.TypeKey(x.AttrInRootNamespace("dgraph.graphql.persisted_query"))
	entry.Value = data
	entry.UserMeta = posting.BitSchemaPosting
	if err := update(entry); err != nil {
		return errors.Wrap(err, "while updating persisted query's type")
	}
	return nil
}

// OfflineUpgradeFrom2011To2103 upgrades a p directory restored from backup of 20.11 to the changes
// in 21.03. It fixes the cors, schema and drops the deprecated types/predicates.
func OfflineUpgradeFrom2011To2103(db *badger.DB) error {
	if err := fixPersistedQuery(db); err != nil {
		return errors.Wrapf(err, "while upgrading persisted query")
	}
	return errors.Wrapf(fixCors(db), "while upgrading cors")
}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Log the full wrapped chain (%+v) to see whether getCors, updateGQLSchemaOffline, or dropDepreciated failed, and address that specific cause.
  2. Re-restore the backup from the original file and rerun the upgrade.
  3. Stop all dgraph processes so the p directory is exclusively available to the upgrade.
  4. Verify disk space and badger directory integrity before retrying.

Example fix

// before
err := upgrade.OfflineUpgradeFrom2011To2103(db)
log.Println(err) // "while upgrading cors: ..." without detail
// after
log.Printf("%+v", err) // full cause chain
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify cors/schema entries are readable before the upgrade
if err := db.View(func(txn *badger.Txn) error {
	_, err := txn.Get([]byte("~graphql.schema"))
	return err
}); err != nil {
	log.Fatalf("schema entry unreadable: %v", err)
}

Type guard

func isCorsUpgradeErr(err error) bool {
	return err != nil && strings.Contains(err.Error(), "while upgrading cors")
}

Try / catch

if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {
	log.Fatalf("cors upgrade failed: %+v", err)
}

Prevention

When it happens

Trigger: Calling OfflineUpgradeFrom2011To2103 where fixCors returns an error: getCors read failure, updateGQLSchemaOffline write failure, or dropDepreciated failure on the restored badger DB.

Common situations: Migrating restored 20.11 backups to 21.03; corrupted or partially-restored p directories; badger I/O errors mid-migration.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/dc14b957a86d647d. Report an issue: GitHub.