-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing Local Session Module because of KeyNotFoundException #56
Comments
Hi @harper10, can you help me with a snippet of your code? |
What code are you looking for? The error happens intermittently, and it recently started happening more recently. Most of the requests are served normally. I think the error is in the LocalSessionModules.cs file where the ConcurrentDictionary is being used to get items from the dictionary. |
Maybe we should consider changing the concurrentdictionary (which is buggy in mono) with a regular dictionary and a synclock object. it would be faster and more lightweight to do.
Mario Di Vece
President & CIO
unosquare.com
…-------- Original message --------
From: Arthur Harper <notifications@github.com>
Date: 12/14/16 1:58 PM (GMT-06:00)
To: unosquare/embedio <embedio@noreply.github.com>
Subject: Re: [unosquare/embedio] Failing Local Session Module because of KeyNotFoundException (#56)
What code are you looking for? The error happens intermittently, and it recently started happening more recently. Most of the requests are served normally. I think the error is in the LocalSessionModules.cs file where the ConcurrentDictionary is being used to get items from the dictionary.
-
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#56 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAVe6vKHg2p6jWWLTA_ENnWtJXC_wvVMks5rIEpggaJpZM4LNVs4>.
|
I think the problem here is that when Sessions[key] is called, key is not guaranteed to be in the concurrentDictionary.
The key could have been removed by another thread. Instead
will make sure that the key is still in the dictionary. |
@harper10 I just updated the nuget (1.2.5) with your suggestion. Let me know if it works for you now. |
I haven't been able to test it because I am getting the same error referenced in #57 |
Can you try again? |
The error has changed to |
Can you paste your project.json? |
@harper10 sometimes I have found that restarting Visual Studio and reopening the solution helps. Xproj projects seems to still be somewhat buggy when it comes to dependencies. Please paste your project.json file here and try my solution also. |
I was able to use the updated nuget client, and I got a different error.
Unfortunately I cannot switch from .Net Version 4.5 because my project is using mono. Are there anyway plans for mono to be supported with the new package? |
You can use NET452 with MONO, I think you only need to use the TargetFrameworkVersion=v4.5 parameter. We use it on Travis to build EmbedIO in Mono.
|
@geoperez i've updated to the last v1.2.8 package and still have this issue. |
Let me take a look |
I'm getting another error: Collection was modified; enumeration operation may not execute. With the following code: var webServerUrl = "http://localhost:9090";
var webServer = new WebServer(webServerUrl);
webServer.RegisterModule(new LocalSessionModule() { Expiration = TimeSpan.FromSeconds(6) });
webServer.RegisterModule(new FallbackModule((ws, ctx) =>
{
return ctx.JsonResponse(new { Message = "OK" });
}));
webServer.RunAsync();
var rnd = new Random();
Parallel.ForEach(Enumerable.Range(0, 50), async (s, t, l) =>
{
await Task.Delay(TimeSpan.FromSeconds(rnd.Next(1, 10)));
using (var webClient = new HttpClient())
{
var data = await webClient.GetStringAsync(webServerUrl);
data.Info();
}
});
Console.ReadKey(); The error it's because the collection change when you delete a session. So I change to create a new collection only for iteration at LocalSessionModule: var currentSessions = new Dictionary<string, SessionInfo>(m_Sessions);
// expire old sessions
foreach (var session in currentSessions)
{
if (session.Value == null) continue;
if (DateTime.Now.Subtract(session.Value.LastActivity) > Expiration)
DeleteSession(session.Value);
} I'll publish this change at version 1.4.2. |
I thought that the |
It should @bufferUnderrun the lock statement creates a critical section in which no more than 1 thread can enter. |
@bufferUnderrun did you test the new version? |
@geoperez yes, test 1 day and run in prod for 2 days. You can close the issue. Thanks for you fix. |
I keep seeing the following error.
The text was updated successfully, but these errors were encountered: