-
Dylan Griffith authored
**TL;DR** Fix a race condition where `IndexStatus` is not created and does not raise error. Need to use `!` and get rid of problematic unique model validation. Looking at the code I notice a logical problem with using `find_or_create_by` alongside a unique model validation. The problem is a race condition which comes from `find_or_create` first checking to see if the record exists. If it does not it tries creating which then invokes the validation which checks again to see if the record exists which finally returns a validation error. But see here we are not using `!` version of `find_or_create` and so this validation error is silently ignored. Since we already have a [`safe_find_or_create_by!`]( https://gitlab.com/gitlab-org/gitlab/-/blob/2b01f1f3420d9177e27418df063aad2e1bda1216/app/models/application_record.rb#L37 ) which is designed for handling this race condition using unique indexes and rescue and seeing that this model already has the [unique index]( https://gitlab.com/gitlab-org/gitlab/-/blob/2b01f1f3420d9177e27418df063aad2e1bda1216/db/structure.sql#L19266 ) we should just get rid of the model validation since it just complicates the error handling. Since this is a pretty weird race condition it seems tricky/contrived to try to create a proper unit test for this case.
afb37c9e
Code owners
:
Zack Cuddy, Florie Guibert, David O'Regan, Ezekiel Kigbo, Phil Hughes, Martin Wortschack, Natalia Tepluhina, Mike Greiling, Tim Zallmann, Kushal Pandya, Paul Slaughter, Enrique Alcántara, Illya Klymov, Andrew Fontaine, Denys Mishunov, Jose Ivan Vargas, Olena Horal-Koretska, Miguel Rincon, Savas Vedova, Jacques Erasmus, Simon Knox, Scott Hampton, Peter Hegman, Mark Florian, Jiaan Louw, Robert Hunt, Nicolò Maria Mezzopera, Vitaly Slobodin, Brandon Labuschagne, Michael Lunøe, Frédéric Caplette, David Pisek, Alexander Turinske, Jannik Lehmann, Anna Vovchenko, Michele Bursi, Marin Jankovski, Amy Phillips, Alessio Caiazza, John Skarbek, Ahmad Tolba, Graeme Gillies, Jenny Kim, Matt Field, Mayra Cabrera, Reuben Pereira, GitLab Release Tools Bot, James Lopez, Peter Leitzen, Huzaifa Iftikhar, Sean McGivern, Douglas Barbosa Alexandre, Stan Hu, Grzegorz Bizon, Rémy Coutable, Kamil Trzciński, Bob Van Landuyt, Alexandru Croitor, Jan Provaznik, Thong Kuah, Heinrich Lee Yu, Imre Farkas, charlie ablett, Dylan Griffith, Albert Salim, Shinya Maeda, Jarka Košanová, James Fargher, Sincheol (David) Kim, Igor Drozdov, Mikołaj Wawrzyniak, Matthias Käppler, Vitali Tatarintev, Patrick Bajao, Fabio Pitino, Lin Jen-Shin, David Fernandez, Mark Chao, Kerri Miller, Alper Akgun, Terri Chu, Gabriel Mazetto, Aleksei Lipniagov, Sean Arnold, Etienne Baqué, Arturo Herrero, Alex Kalderimis, Nikola Milojevic, Dmitry Gruzd, Doug Stull, Alex Pooley, Robert May, Vasilii Iakliushin, Andy Soiron, Tetiana Chupryna, Allison Browne, Pavel Shutsin, Furkan Ayhan, Marius Bobin, Marc Shaw, Ethan Urie, Michael Kozono, Ash McKenzie, Luke Duncalfe, Max Woolf, George Koltsov, Allen Cook, Steve Abrams, Tiger Watson, Krasimir Angelov, Alex Ives, João Alexandre Cunha, Adam Hegyi, Simon Tomlinson, Diogo Frazão, Chloe Liu, Tiffany Rea, Ramya Authappan, Anastasia McDonald, Andrejs Cunskis, Dan Davison, Mark Lapierre, Sanad Liaquat, Hordur Freyr Yngvason, Cheryl Li, Marcel Amirault, Laura Montemayor, Jacob Vosmaer, and Kyle Wiebers