Monorepo for Tangled tangled.org

knotserver/xrpc: defer plc submission until repo setup succeeds #1285

merged opened by kppcn.tngl.sh targeting master

Previously, CreateRepo submitted the PLC DID before the remaining local setup steps had completed. If RBAC setup or hook installation failed after that point, the handler cleaned up local state but still left behind a published DID with no corresponding repo on disk. Move PLC submission to the end of the create flow so the DID is only published after local repo setup succeeds. Also roll back repo RBAC state during cleanup, and treat hook setup failure as fatal instead of silently continuing.

Labels

None yet.

assignee
Participants 2
AT URI
at://did:plc:guezqvyt7qge46ojzkofdjft/sh.tangled.repo.pull/3mire6fqj3522
+25 -13
Diff #0
+25 -13
knotserver/xrpc/create_repo.go
··· 145 145 146 146 repoPath, _ := securejoin.SecureJoin(h.Config.Repo.ScanPath, repoDid) 147 147 rbacPath := repoDid 148 + repoAddedToRBAC := false 148 149 149 150 cleanup := func() { 150 151 if rmErr := os.RemoveAll(repoPath); rmErr != nil { ··· 153 154 } 154 155 155 156 cleanupAll := func() { 157 + if repoAddedToRBAC { 158 + if rmErr := h.Enforcer.RemoveRepo(actorDid.String(), rbac.ThisServer, rbacPath); rmErr != nil { 159 + l.Error("failed to clean up repo permissions", "error", rmErr.Error()) 160 + } 161 + } 156 162 cleanup() 157 163 if delErr := h.Db.DeleteRepoKey(repoDid); delErr != nil { 158 164 l.Error("failed to clean up repo key", "error", delErr.Error()) ··· 195 201 } 196 202 } 197 203 198 - if prepared != nil { 199 - plcCtx, plcCancel := context.WithTimeout(context.Background(), 30*time.Second) 200 - defer plcCancel() 201 - if err := prepared.Submit(plcCtx); err != nil { 202 - l.Error("submitting to PLC directory", "error", err.Error()) 203 - cleanupAll() 204 - writeError(w, xrpcerr.GenericError(fmt.Errorf("PLC directory submission failed: %w", err)), http.StatusInternalServerError) 205 - return 206 - } 207 - } 208 - 209 204 // add perms for this user to access the repo 210 205 err = h.Enforcer.AddRepo(actorDid.String(), rbac.ThisServer, rbacPath) 211 206 if err != nil { ··· 214 209 writeError(w, xrpcerr.GenericError(err), http.StatusInternalServerError) 215 210 return 216 211 } 212 + repoAddedToRBAC = true 217 213 218 - hook.SetupRepo( 214 + if err := hook.SetupRepo( 219 215 hook.Config( 220 216 hook.WithScanPath(h.Config.Repo.ScanPath), 221 217 hook.WithInternalApi(h.Config.Server.InternalListenAddr), 222 218 ), 223 219 repoPath, 224 - ) 220 + ); err != nil { 221 + l.Error("setting up repo hooks", "error", err.Error()) 222 + cleanupAll() 223 + writeError(w, xrpcerr.GenericError(err), http.StatusInternalServerError) 224 + return 225 + } 226 + 227 + if prepared != nil { 228 + plcCtx, plcCancel := context.WithTimeout(context.Background(), 30*time.Second) 229 + defer plcCancel() 230 + if err := prepared.Submit(plcCtx); err != nil { 231 + l.Error("submitting to PLC directory", "error", err.Error()) 232 + cleanupAll() 233 + writeError(w, xrpcerr.GenericError(fmt.Errorf("PLC directory submission failed: %w", err)), http.StatusInternalServerError) 234 + return 235 + } 236 + } 225 237 226 238 // HACK: request crawl for this repository 227 239 // Users won't want to sync entire network from their local knotmirror.

History

1 round 1 comment
sign up or login to add to the discussion
kppcn.tngl.sh submitted #0
expand 1 comment
pull request successfully merged