diff --git a/Site5/Pages/v5/Public/Initialize.aspx.cs b/Site5/Pages/v5/Public/Initialize.aspx.cs index 1d037729..6aa0ecc2 100644 --- a/Site5/Pages/v5/Public/Initialize.aspx.cs +++ b/Site5/Pages/v5/Public/Initialize.aspx.cs @@ -700,6 +700,23 @@ namespace Swarmops.Frontend.Pages.v5.Public } } + // Protect against race condition on a really really slow server: wait until there is a first person or 15 seconds have expired + + DateTime utcTimeout = DateTime.UtcNow.AddSeconds (15); + People people = People.GetAll(); + while (people.Count < 1 && DateTime.UtcNow < utcTimeout) + { + Thread.Sleep (500); + people = People.GetAll(); + } + + if (people.Count < 1) + { + throw new InvalidOperationException("First person has not been created despite 15-second timeout; cannot login"); + } + + // Get authenticated person + Person expectedPersonOne = Authentication.Authenticate ("1", this.TextFirstUserPassword1.Text);