ericberman / MyFlightbookWeb

The website and service for MyFlightbook
49 stars 18 forks source link

Periodic crash in UserQualifies #1235

Closed ericberman closed 4 months ago

ericberman commented 5 months ago
    public static bool UserQualifies(string szUser, Gratuity.GratuityTypes gt)
    {
        Profile pf = Profile.GetUser(szUser);
        string szSessionKey = SessionKeyForUser(szUser, gt);
        if (pf.AssociatedData.TryGetValue(szSessionKey, out object value))
            return (bool)value;

        List<EarnedGratuity> lst = GratuitiesForUser(szUser, gt);

==> return (bool) (pf.AssociatedData[szSessionKey] = lst.Count != 0 && lst[0].ExpirationDate.CompareTo(DateTime.Now) > 0); }

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at MyFlightbook.Payments.EarnedGratuity.UserQualifies(String szUser, GratuityTypes gt) in C:\Users\ericb\GitHub\MyFlightbookWeb\MyFlightbook.Web\AppCode\Utility\Payment.cs:line 1020

Flushing the cache makes the issue go away.

ericberman commented 5 months ago

Looks like this might need a simple modification in Profile:

public IDictionary<string, object> AssociatedData { get; private set; } = new ConcurrentDictionary<string, object>();

This could be a thread contention issue.