Skip to content

Commit

Permalink
Ensure lfs check within transaction
Browse files Browse the repository at this point in the history
The previous code made it possible for a race condition to occur whereby a LFSMetaObject could be checked into the database twice. We should check if the LFSMetaObject is within the database and insert it if not in one transaction.
  • Loading branch information
zeripath committed Jan 20, 2019
1 parent 9618f24 commit 2456cb6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions models/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ const (
func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
var err error

has, err := x.Get(m)
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}

has, err := sess.Get(m)
if err != nil {
return nil, err
}

if has {
m.Existing = true
return m, nil
}

sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
return m, sess.Commit()
}

if _, err = sess.Insert(m); err != nil {
Expand Down

0 comments on commit 2456cb6

Please sign in to comment.