Comments (19)
Hi @harper10, can you help me with a snippet of your code?
from embedio.
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.
from embedio.
from embedio.
I think the problem here is that when Sessions[key] is called, key is not guaranteed to be in the concurrentDictionary.
var allKeys = Sessions.Keys.ToArray();
foreach (var key in allKeys)
{
var sessionInfo = Sessions[key];
if (DateTime.Now.Subtract(sessionInfo.LastActivity) > Expiration)
Sessions.TryRemove(key, out sessionInfo);
}
The key could have been removed by another thread. Instead
var allKeys = Sessions.Keys.ToArray();
foreach (var key in allKeys)
{
SessionInfo sessionInfo;
if (Sessions.TryGetValue(key, out sessionInfo))
{
if (DateTime.Now.Subtract(sessionInfo.LastActivity) > Expiration)
Sessions.TryRemove(key, out sessionInfo);
}
}
will make sure that the key is still in the dictionary.
from embedio.
@harper10 I just updated the nuget (1.2.5) with your suggestion. Let me know if it works for you now.
from embedio.
I haven't been able to test it because I am getting the same error referenced in #57
from embedio.
Can you try again?
from embedio.
The error has changed to
'EmbedIO' already has a dependency defined for 'System.Collections.Specialized'
from embedio.
Can you paste your project.json?
from embedio.
@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.
from embedio.
I was able to use the updated nuget client, and I got a different error.
Could not install package 'EmbedIO 1.2.7'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework.
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?
from embedio.
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.
xbuild Unosquare.Labs.EmbedIO.Lib.sln /p:"TargetFrameworkVersion=v4.5;Configuration=Release"
from embedio.
@geoperez i've updated to the last v1.2.8 package and still have this issue.
from embedio.
Let me take a look
from embedio.
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.
from embedio.
I thought that the lock(SessionsSyncLock)
forced threads to sync ? So it does not work this way ?
I will test it
from embedio.
It should @bufferUnderrun the lock statement creates a critical section in which no more than 1 thread can enter.
from embedio.
@bufferUnderrun did you test the new version?
from embedio.
@geoperez yes, test 1 day and run in prod for 2 days. You can close the issue. Thanks for you fix.
from embedio.
Related Issues (20)
- How to send statuscode 202 HOT 1
- EmbedIO 3.5.0 NuGet package references wrong/old version of Unosquare.Swan.Lite HOT 22
- System.ObjectDisposedException when processing multiple requests at once HOT 2
- WithZipFile should open a read only handle(or have the option to) HOT 2
- FileModule or StaticFolderModule get stuck returning medium files HOT 4
- Add XML as response type
- EmbedIO Dual-Stack Localhost Listener Causes Empty Replies HOT 1
- How can I custom the Server header HOT 2
- Disable request logging only
- Cookies issue
- EmbedIO.Samples console app does not work when PublishAot is set to true HOT 2
- Web Server does not work in Xamarin.iOS (IOS-17) HOT 3
- How to report progess via api - event-stream
- HttpContext.OnClose not firing HOT 1
- Getting rid of double quotes around strings in a Web API response (turning off JSON serialization) HOT 1
- Issue Serving Static Folder Xamarin ( 3.5.2) Forms on Android
- Request.Url mixing up http and https
- server stop responding after some time HOT 4
- The return array is empty. HOT 1
- Crash the webserver and restart the main application
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedio.