From e52bff23f08bf3270fcb618b47b13652c86abbf9 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 13 Mar 2016 19:01:48 +0100 Subject: [PATCH] Another hardening to Init --- Site5/Pages/v5/Public/Initialize.aspx.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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);