Giter Club home page Giter Club logo

Comments (19)

geoperez avatar geoperez commented on August 28, 2024

Hi @harper10, can you help me with a snippet of your code?

from embedio.

harper10 avatar harper10 commented on August 28, 2024

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.

mariodivece avatar mariodivece commented on August 28, 2024

from embedio.

harper10 avatar harper10 commented on August 28, 2024

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.

geoperez avatar geoperez commented on August 28, 2024

@harper10 I just updated the nuget (1.2.5) with your suggestion. Let me know if it works for you now.

from embedio.

harper10 avatar harper10 commented on August 28, 2024

I haven't been able to test it because I am getting the same error referenced in #57

from embedio.

geoperez avatar geoperez commented on August 28, 2024

Can you try again?

from embedio.

harper10 avatar harper10 commented on August 28, 2024

The error has changed to
'EmbedIO' already has a dependency defined for 'System.Collections.Specialized'

from embedio.

geoperez avatar geoperez commented on August 28, 2024

Can you paste your project.json?

from embedio.

mariodivece avatar mariodivece commented on August 28, 2024

@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.

harper10 avatar harper10 commented on August 28, 2024

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.

geoperez avatar geoperez commented on August 28, 2024

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.

bufferUnderrun avatar bufferUnderrun commented on August 28, 2024

@geoperez i've updated to the last v1.2.8 package and still have this issue.

from embedio.

geoperez avatar geoperez commented on August 28, 2024

Let me take a look

from embedio.

geoperez avatar geoperez commented on August 28, 2024

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.

bufferUnderrun avatar bufferUnderrun commented on August 28, 2024

I thought that the lock(SessionsSyncLock) forced threads to sync ? So it does not work this way ?
I will test it

from embedio.

mariodivece avatar mariodivece commented on August 28, 2024

It should @bufferUnderrun the lock statement creates a critical section in which no more than 1 thread can enter.

from embedio.

geoperez avatar geoperez commented on August 28, 2024

@bufferUnderrun did you test the new version?

from embedio.

bufferUnderrun avatar bufferUnderrun commented on August 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.