Fix unclosed DB transactions in subscriber search

This commit is contained in:
Kailash Nadh 2019-12-05 21:27:31 +05:30
parent 6b6dc59067
commit 6747a95b3d
2 changed files with 2 additions and 2 deletions

View File

@ -110,6 +110,7 @@ func (q *Queries) compileSubscriberQueryTpl(exp string, db *sqlx.DB) (string, er
if err != nil { if err != nil {
return "", err return "", err
} }
defer tx.Rollback()
// Perform the dry run. // Perform the dry run.
if exp != "" { if exp != "" {
@ -117,7 +118,6 @@ func (q *Queries) compileSubscriberQueryTpl(exp string, db *sqlx.DB) (string, er
} }
stmt := fmt.Sprintf(q.QuerySubscribersTpl, exp) stmt := fmt.Sprintf(q.QuerySubscribersTpl, exp)
if _, err := tx.Exec(stmt, true, pq.Int64Array{}); err != nil { if _, err := tx.Exec(stmt, true, pq.Int64Array{}); err != nil {
tx.Rollback()
return "", err return "", err
} }

View File

@ -114,10 +114,10 @@ func handleQuerySubscribers(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
fmt.Sprintf("Error preparing query: %v", pqErrMsg(err))) fmt.Sprintf("Error preparing query: %v", pqErrMsg(err)))
} }
defer tx.Rollback()
// Run the query. // Run the query.
if err := tx.Select(&out.Results, stmt, listIDs, "id", pg.Offset, pg.Limit); err != nil { if err := tx.Select(&out.Results, stmt, listIDs, "id", pg.Offset, pg.Limit); err != nil {
tx.Rollback()
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
fmt.Sprintf("Error querying subscribers: %v", pqErrMsg(err))) fmt.Sprintf("Error querying subscribers: %v", pqErrMsg(err)))
} }