Browse Source

Fix SQLite deadlock when creating user

This avoids reading from the database after a transaction has been
started in CreateUser(), fixing the deadlock that occurred before.

Closes #53
tags/v0.7.0
Matt Baer 5 years ago
parent
commit
1c58c64c7c
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      database.go

+ 4
- 4
database.go View File

@@ -155,16 +155,16 @@ func (db *datastore) dateSub(l int, unit string) string {
}

func (db *datastore) CreateUser(u *User, collectionTitle string) error {
if db.PostIDExists(u.Username) {
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
}

// New users get a `users` and `collections` row.
t, err := db.Begin()
if err != nil {
return err
}

if db.PostIDExists(u.Username) {
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
}

// 1. Add to `users` table
// NOTE: Assumes User's Password is already hashed!
res, err := t.Exec("INSERT INTO users (username, password, email) VALUES (?, ?, ?)", u.Username, u.HashedPass, u.Email)


Loading…
Cancel
Save