Loading CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ## [Unreleased] ### Fixed - Set gateway timeout to match idle timeout value. - Reliably release database resources before moving from one query to the next. ## [2.3.1] - 2019-01-04 ### Added Loading server/console_account.go +3 −1 Original line number Diff line number Diff line Loading @@ -116,12 +116,14 @@ func (s *ConsoleServer) ListAccounts(ctx context.Context, in *empty.Empty) (*con userIDs := make([]string, 0) for rows.Next() { var userID sql.NullString if rows.Scan(&userID); err != nil { if err = rows.Scan(&userID); err != nil { rows.Close() s.logger.Error("Could not list users.", zap.Error(err)) return nil, status.Error(codes.Internal, "An error occurred while trying to list users.") } userIDs = append(userIDs, userID.String) } rows.Close() accounts := make([]*api.Account, 0) for _, id := range userIDs { Loading server/core_authenticate.go +16 −15 Original line number Diff line number Diff line Loading @@ -627,20 +627,27 @@ func importFacebookFriends(ctx context.Context, logger *zap.Logger, db *sql.DB, if err != nil { return err } defer rows.Close() var id string query = "UPDATE users SET edge_count = edge_count - 1 WHERE id = $1" statements := make([]string, 0) params := make([]interface{}, 0) for rows.Next() { // Update edge count to reflect each removed friend. var id string err = rows.Scan(&id) if err != nil { rows.Close() return err } result, err := tx.ExecContext(ctx, query, id) params = append(params, id) statements = append(statements, "$"+strconv.Itoa(len(params))) } rows.Close() if len(statements) > 0 { query = "UPDATE users SET edge_count = edge_count - 1 WHERE id IN (" + strings.Join(statements, ",") + ")" result, err := tx.ExecContext(ctx, query, params...) if err != nil { return err } if rowsAffectedCount, _ := result.RowsAffected(); rowsAffectedCount != 1 { if rowsAffectedCount, _ := result.RowsAffected(); rowsAffectedCount != int64(len(statements)) { return errors.New("error updating edge count after friend reset") } } Loading Loading @@ -685,15 +692,9 @@ func importFacebookFriends(ctx context.Context, logger *zap.Logger, db *sql.DB, for _, friendID := range possibleFriendIDs { position := time.Now().UTC().UnixNano() var r *sql.Rows r, err = tx.QueryContext(ctx, "SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3", userID, friendID) if r.Next() { // User has previously blocked this friend, skip it. r.Close() continue } if err != nil { var state sql.NullInt64 err = tx.QueryRowContext(ctx, "SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3", userID, friendID).Scan(&state) if err != nil && err != sql.ErrNoRows { logger.Error("Error checking block status in Facebook friend import.", zap.Error(err)) continue } Loading server/core_channel.go +2 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: logger.Error("Error listing channel messages", zap.Error(err)) return nil, err } defer rows.Close() messages := make([]*api.ChannelMessage, 0, limit) var nextCursor, prevCursor *channelMessageListCursor Loading Loading @@ -152,6 +151,7 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: err = rows.Scan(&dbId, &dbCode, &dbSenderId, &dbUsername, &dbContent, &dbCreateTime, &dbUpdateTime) if err != nil { rows.Close() logger.Error("Error parsing listed channel messages", zap.Error(err)) return nil, err } Loading Loading @@ -182,6 +182,7 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: } } } rows.Close() if incomingCursor != nil && !incomingCursor.IsNext { // If this was a previous page listing, flip the results to their normal order and swap the cursors. Loading server/core_group.go +3 −3 Original line number Diff line number Diff line Loading @@ -329,8 +329,6 @@ WHERE (id = $1) AND (disable_time = '1970-01-01 00:00:00')` // Errors here will not cause the join operation to fail. logger.Error("Error looking up group admins to notify of join request.", zap.Error(err)) } else { defer rows.Close() for rows.Next() { var id string if err = rows.Scan(&id); err != nil { Loading @@ -352,6 +350,7 @@ WHERE (id = $1) AND (disable_time = '1970-01-01 00:00:00')` }, } } rows.Close() } if len(notifications) > 0 { Loading Loading @@ -1264,7 +1263,6 @@ WHERE group_edge.destination_id = $1` logger.Debug("Could not list groups for a user.", zap.Error(err), zap.String("user_id", userID.String())) return err } defer rows.Close() deleteGroupsAndRelationships := make([]uuid.UUID, 0) deleteRelationships := make([]uuid.UUID, 0) Loading @@ -1276,6 +1274,7 @@ WHERE group_edge.destination_id = $1` var userState sql.NullInt64 if err := rows.Scan(&id, &edgeCount, &userState); err != nil { rows.Close() logger.Error("Could not parse rows when listing groups for a user.", zap.Error(err), zap.String("user_id", userID.String())) return err } Loading @@ -1291,6 +1290,7 @@ WHERE group_edge.destination_id = $1` deleteRelationships = append(deleteRelationships, groupID) } } rows.Close() countOtherSuperadminsQuery := "SELECT COUNT(source_id) FROM group_edge WHERE source_id = $1 AND destination_id != $2 AND state = 0" for _, g := range checkForOtherSuperadmins { Loading Loading
CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ## [Unreleased] ### Fixed - Set gateway timeout to match idle timeout value. - Reliably release database resources before moving from one query to the next. ## [2.3.1] - 2019-01-04 ### Added Loading
server/console_account.go +3 −1 Original line number Diff line number Diff line Loading @@ -116,12 +116,14 @@ func (s *ConsoleServer) ListAccounts(ctx context.Context, in *empty.Empty) (*con userIDs := make([]string, 0) for rows.Next() { var userID sql.NullString if rows.Scan(&userID); err != nil { if err = rows.Scan(&userID); err != nil { rows.Close() s.logger.Error("Could not list users.", zap.Error(err)) return nil, status.Error(codes.Internal, "An error occurred while trying to list users.") } userIDs = append(userIDs, userID.String) } rows.Close() accounts := make([]*api.Account, 0) for _, id := range userIDs { Loading
server/core_authenticate.go +16 −15 Original line number Diff line number Diff line Loading @@ -627,20 +627,27 @@ func importFacebookFriends(ctx context.Context, logger *zap.Logger, db *sql.DB, if err != nil { return err } defer rows.Close() var id string query = "UPDATE users SET edge_count = edge_count - 1 WHERE id = $1" statements := make([]string, 0) params := make([]interface{}, 0) for rows.Next() { // Update edge count to reflect each removed friend. var id string err = rows.Scan(&id) if err != nil { rows.Close() return err } result, err := tx.ExecContext(ctx, query, id) params = append(params, id) statements = append(statements, "$"+strconv.Itoa(len(params))) } rows.Close() if len(statements) > 0 { query = "UPDATE users SET edge_count = edge_count - 1 WHERE id IN (" + strings.Join(statements, ",") + ")" result, err := tx.ExecContext(ctx, query, params...) if err != nil { return err } if rowsAffectedCount, _ := result.RowsAffected(); rowsAffectedCount != 1 { if rowsAffectedCount, _ := result.RowsAffected(); rowsAffectedCount != int64(len(statements)) { return errors.New("error updating edge count after friend reset") } } Loading Loading @@ -685,15 +692,9 @@ func importFacebookFriends(ctx context.Context, logger *zap.Logger, db *sql.DB, for _, friendID := range possibleFriendIDs { position := time.Now().UTC().UnixNano() var r *sql.Rows r, err = tx.QueryContext(ctx, "SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3", userID, friendID) if r.Next() { // User has previously blocked this friend, skip it. r.Close() continue } if err != nil { var state sql.NullInt64 err = tx.QueryRowContext(ctx, "SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3", userID, friendID).Scan(&state) if err != nil && err != sql.ErrNoRows { logger.Error("Error checking block status in Facebook friend import.", zap.Error(err)) continue } Loading
server/core_channel.go +2 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: logger.Error("Error listing channel messages", zap.Error(err)) return nil, err } defer rows.Close() messages := make([]*api.ChannelMessage, 0, limit) var nextCursor, prevCursor *channelMessageListCursor Loading Loading @@ -152,6 +151,7 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: err = rows.Scan(&dbId, &dbCode, &dbSenderId, &dbUsername, &dbContent, &dbCreateTime, &dbUpdateTime) if err != nil { rows.Close() logger.Error("Error parsing listed channel messages", zap.Error(err)) return nil, err } Loading Loading @@ -182,6 +182,7 @@ WHERE stream_mode = $1 AND stream_subject = $2::UUID AND stream_descriptor = $3: } } } rows.Close() if incomingCursor != nil && !incomingCursor.IsNext { // If this was a previous page listing, flip the results to their normal order and swap the cursors. Loading
server/core_group.go +3 −3 Original line number Diff line number Diff line Loading @@ -329,8 +329,6 @@ WHERE (id = $1) AND (disable_time = '1970-01-01 00:00:00')` // Errors here will not cause the join operation to fail. logger.Error("Error looking up group admins to notify of join request.", zap.Error(err)) } else { defer rows.Close() for rows.Next() { var id string if err = rows.Scan(&id); err != nil { Loading @@ -352,6 +350,7 @@ WHERE (id = $1) AND (disable_time = '1970-01-01 00:00:00')` }, } } rows.Close() } if len(notifications) > 0 { Loading Loading @@ -1264,7 +1263,6 @@ WHERE group_edge.destination_id = $1` logger.Debug("Could not list groups for a user.", zap.Error(err), zap.String("user_id", userID.String())) return err } defer rows.Close() deleteGroupsAndRelationships := make([]uuid.UUID, 0) deleteRelationships := make([]uuid.UUID, 0) Loading @@ -1276,6 +1274,7 @@ WHERE group_edge.destination_id = $1` var userState sql.NullInt64 if err := rows.Scan(&id, &edgeCount, &userState); err != nil { rows.Close() logger.Error("Could not parse rows when listing groups for a user.", zap.Error(err), zap.String("user_id", userID.String())) return err } Loading @@ -1291,6 +1290,7 @@ WHERE group_edge.destination_id = $1` deleteRelationships = append(deleteRelationships, groupID) } } rows.Close() countOtherSuperadminsQuery := "SELECT COUNT(source_id) FROM group_edge WHERE source_id = $1 AND destination_id != $2 AND state = 0" for _, g := range checkForOtherSuperadmins { Loading