Skip to content

Commit

Permalink
there is a race where apps can be modified during bind/unbind
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Apr 26, 2024
1 parent 7255c58 commit fdf330d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,14 @@ func bindServiceInstance(w http.ResponseWriter, r *http.Request, t auth.Token) (
return err
}
defer func() { evt.Done(err) }()

// NOTE(wpjunior): there is a race where apps can be modified during the retry-lock designed for the events
// read more about event retry-lock at event/event.go on newEvt function
// to avoid an outdated app fetching from database again
a, err = app.GetByName(ctx, appName)
if err != nil {
return err
}
w.Header().Set("Content-Type", "application/x-json-stream")
keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 30*time.Second, "")
defer keepAliveWriter.Stop()
Expand Down Expand Up @@ -1633,6 +1641,15 @@ func unbindServiceInstance(w http.ResponseWriter, r *http.Request, t auth.Token)
return err
}
defer func() { evt.Done(err) }()

// NOTE(wpjunior): there is a race where apps can be modified during the retry-lock designed for the events
// read more about event retry-lock at event/event.go on newEvt function
// to avoid an outdated app fetching from database again
a, err = app.GetByName(ctx, appName)
if err != nil {
return err
}

w.Header().Set("Content-Type", "application/x-json-stream")
keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 30*time.Second, "")
defer keepAliveWriter.Stop()
Expand Down

0 comments on commit fdf330d

Please sign in to comment.