Skip to content

Gracefully handle orphaned member invites

Stan Hu requested to merge sh-fix-orphaned-invited-members into master

For some reason, member invite tokens can be cleared without saving an associated user. These entries cause 500 errors to show up in the member view, and they can't be fixed easily without manually deleting entries in the database.

This commit does two things:

  1. Removes these orphaned entries from the database.
  2. Gracefully handles them in the code: log an exception with details and provide a message in the remove button that allows project/group admins to delete these entries.

On GitLab.com, the migration removes 19 rows with the latest orphaned entry created on 2020-04-16. That suggests the underlying bug is still there but does not happen very often.

Closes #23198 (closed)

Migration on GitLab.com

gitlabhq_production=# select updated_at from members where user_id IS NULL AND invite_token IS NULL AND invite_accepted_at IS NOT NULL;
         updated_at
----------------------------
 2020-04-16 07:48:33.168659
 2020-04-10 15:52:39.520485
 2020-04-03 13:36:43.701215
 2020-04-03 13:35:07.224005
 2020-03-16 11:51:57.68985
 2020-03-11 04:01:43.723087
 2020-03-10 20:10:48.630674
 2020-03-10 03:16:11.545292
 2020-02-18 05:43:53.003019
 2020-02-10 04:20:41.88529
 2020-01-30 12:34:53.571685
 2020-01-07 07:38:20.024979
 2020-01-07 02:21:47.165356
 2019-12-19 14:34:57.90654
 2019-12-05 08:26:26.827587
 2019-11-12 08:09:43.595101
 2019-11-05 02:02:53.000147
 2019-11-01 16:11:46.012656
 2019-11-01 16:10:59.423287
(19 rows)

EXPLAIN output

gitlabhq_production=# EXPLAIN ANALYZE select updated_at from members where user_id IS NULL AND invite_token IS NULL AND invite_accepted_at IS NOT NULL;
                                                                  QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
 Index Scan using index_members_on_user_id on members  (cost=0.44..239481.31 rows=24857 width=8) (actual time=27.938..756.053 rows=19 loops=1)
   Index Cond: (user_id IS NULL)
   Filter: ((invite_token IS NULL) AND (invite_accepted_at IS NOT NULL))
   Rows Removed by Filter: 772995
 Planning time: 0.099 ms
 Execution time: 756.088 ms
(6 rows

Screenshot

image

Edited by 🤖 GitLab Bot 🤖

Merge request reports