tonerdo / dotnet-env

A .NET library to load environment variables from .env files
MIT License
427 stars 50 forks source link

BUG FakeEnvVars is not threadsafe #101

Closed coenm closed 1 month ago

coenm commented 1 month ago

Got the following exception:

Error Message: System.InvalidOperationException : Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.

with the following stacktrace:

Stack Trace: at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)

at DotNetEnv.Parsers.DoNotSetEnvVar(KeyValuePair`2 kvp)

at Sprache.Parse.<>c (stripped Sprache for brevity )

at Sprache.ParserExtensions.Parse[T](Parser`1 parser, String input)

at DotNetEnv.Parsers.ParseDotenvFile(String contents, Func`2 tranform)

at DotNetEnv.Env.LoadContents(String contents, LoadOptions options)

A fix would be to make the collection threadsafe by using a ConcurrentDictionary.

rogusdev commented 1 month ago

Thanks for catching that.

coenm commented 1 month ago

You are welcome. Thanks for merging. Any idea when to publish a new release?

rogusdev commented 1 month ago

Should be up now