{"record":{"id":"b7a7b7c14acde6e9","repo":"Billionmail/BillionMail","slug":"failed-to-apply-configurations-but-rollback-succe","errorCode":null,"errorMessage":"failed to apply configurations, but rollback succeeded: %v","messagePattern":"failed to apply configurations, but rollback succeeded: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/multi_ip_domain/config_manager.go","lineNumber":72,"sourceCode":"// ApplyConfigsWithRollback Apply configurations and rollback on failure\nfunc (m *ConfigManager) ApplyConfigsWithRollback(ctx context.Context, configs []map[string]interface{}) error {\n\n\tm.fileLocker.Lock()\n\tdefer m.fileLocker.Unlock()\n\n\tbackups, err := m.createBackups(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create backup: %v\", err)\n\t}\n\n\t// Apply configurations\n\tif err := m.applyConfigs(ctx, configs); err != nil {\n\n\t\tg.Log().Debugf(ctx, \"Failed to apply configurations, rolling back... Error: %v\", err)\n\t\tif rollbackErr := m.rollback(ctx, backups); rollbackErr != nil {\n\t\t\treturn fmt.Errorf(\"failed to apply configurations: %v, rollback also failed: %v\", err, rollbackErr)\n\t\t}\n\t\treturn fmt.Errorf(\"failed to apply configurations, but rollback succeeded: %v\", err)\n\t}\n\n\tm.cleanupBackups(ctx, backups)\n\treturn nil\n}\n\n// createBackups Create backups for Postfix's main.cf and master.cf\nfunc (m *ConfigManager) createBackups(ctx context.Context) (map[string]string, error) {\n\tbackups := make(map[string]string)\n\n\tfiles := []string{PostfixMainCfPath, PostfixMasterCfPath}\n\n\tfor _, file := range files {\n\t\tif gfile.Exists(file) {\n\t\t\tcontent, err := ioutil.ReadFile(file)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to read file %s: %v\", file, err)\n\t\t\t}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/multi_ip_domain/config_manager.go#L54-L90","documentation":"ApplyConfigsWithRollback failed to apply the new configurations, but successfully restored the original files from backups. The system is back in its pre-apply state; the wrapped error explains why the apply failed. This is a 'safe failure' outcome and should be retried after fixing the underlying cause.","triggerScenarios":"m.applyConfigs(ctx, configs) returned an error — e.g. writing a rendered postconf/main.cf failed, template rendering failed, or a validation step inside applyConfigs rejected the config — and m.rollback(ctx, backups) completed without error.","commonSituations":"Invalid config content generated for a domain/IP mapping; permission or disk errors during config write; hostname/IP validation failing for the supplied inputs; interrupted network mounts during apply.","solutions":["Read the wrapped inner error (%v) to find why applyConfigs failed and fix that input/config","Validate config inputs (IPs, domains, hostnames) before calling ApplyConfigsWithRollback","Re-run the operation once the root cause is fixed — state was cleanly rolled back so it is safe to retry","Check logs around 'Failed to apply configurations, rolling back...' for the apply error detail"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := validateConfigs(configs); err != nil { // check IPs, domains, hostnames\n    return err\n}\nfor _, f := range []string{PostfixMainCfPath, PostfixMasterCfPath} {\n    if err := writableFile(f); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"err := manager.ApplyConfigsWithRollback(ctx, configs)\nif err != nil && strings.Contains(err.Error(), \"but rollback succeeded\") {\n    // safe to retry after fixing cause\n    log.Warnf(\"apply failed, rolled back cleanly: %v\", err)\n    fixCause(err) // e.g. correct invalid config input\n    err = manager.ApplyConfigsWithRollback(ctx, configs)\n}","preventionTips":["Validate config inputs (IP/domain/hostname syntax) before applying","Log the inner apply error — rollback masks it as the second clause of the message","Fix root cause then re-run; state is clean after successful rollback","Watch for repeated apply failures indicating environment drift"],"tags":["configuration","rollback","postfix"],"backgroundTag":"config-apply-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}