Skip to content
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

Fix: ReconfigExistingLoggers sometimes throws an Exception #2228 #2229

Merged
merged 4 commits into from
Aug 8, 2017

Conversation

jpdillingham
Copy link
Contributor

Fixes #2228

@snakefoot
Copy link
Contributor

If the problem is caused by the Values-Collection-Enumerator is detecting that the dictionary has been modified while enumerating, then the correct fix is to make the clone under a lock (See alternative solution here: #2131)

@jpdillingham
Copy link
Contributor Author

I've added a lock around the references to loggerCache. I was hesitant to do this from the start because this is my first time looking at the code and I was concerned about reciprocal effects.

@codecov
Copy link

codecov bot commented Jul 29, 2017

Codecov Report

Merging #2229 into release-4.4.12 will increase coverage by <1%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##           release-4.4.12   #2229    +/-   ##
===============================================
+ Coverage              81%     81%   +<1%     
===============================================
  Files                 291     291            
  Lines               20135   20134     -1     
  Branches             2394    2394            
===============================================
+ Hits                16354   16366    +12     
  Misses               3152    3152            
+ Partials              629     616    -13

@snakefoot
Copy link
Contributor

snakefoot commented Jul 29, 2017

Not sure I understand why you have added a new lock-object. There is already LogFactory.syncRoot which is used all other places before accessing/modifying the loggerCache. This new lock-object doesn't have any effect, besides serializing readers.

Why not make the change that I initially suggested here: #2131 ?

Could even optimize it, so you change LoggerCache.Loggers-property to return an List<Logger>, instead of allocating even more lists.

@jpdillingham
Copy link
Contributor Author

I see what you mean now. Apologies, I was trying to fix the issue without getting into the weeds.

@snakefoot
Copy link
Contributor

@jpdillingham Guess you can remove the stale comment:

//new list to avoid "Collection was modified; enumeration operation may not execute"

@304NotModified 304NotModified added the bug Bug report / Bug fix label Aug 4, 2017
@304NotModified
Copy link
Member

Could you rebase this one on branch release-4.4.12? (and change this PR, not sure if you could do that)

@jpdillingham
Copy link
Contributor Author

I believe this will do it.

@304NotModified 304NotModified changed the base branch from master to release-4.4.12 August 4, 2017 12:56
@@ -1348,7 +1350,7 @@ private IEnumerable<Logger> GetLoggers()
List<Logger> values = new List<Logger>(loggerCache.Count);

//new list for prevent InvalidOperationException on Travis/Mono.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also an old comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that is irrelevant now due to the upstream lock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpdillingham If removing the comment, then you should also remove the ToList()-operation.

@jpdillingham
Copy link
Contributor Author

Just to follow up, I've made all of the requested changes and this should be ready to merge whenever you're ready.

@304NotModified
Copy link
Member

Thanks for the reminder. @snakefoot this change is also OK for you isn't?

@304NotModified 304NotModified self-assigned this Aug 8, 2017
@snakefoot
Copy link
Contributor

snakefoot commented Aug 8, 2017 via email

@304NotModified 304NotModified merged commit 010eb5d into NLog:release-4.4.12 Aug 8, 2017
@304NotModified 304NotModified added this to the 4.4.12 milestone Aug 8, 2017
@304NotModified
Copy link
Member

Online!

https://www.nuget.org/packages/NLog/4.4.12

Thanks @jpdillingham !

@dtatcox
Copy link

dtatcox commented Sep 19, 2017

I just got this same exception from ReconfigExistingLoggers and I am 100% sure i'm on 4.4.12.

@304NotModified
Copy link
Member

Please create a new issue, including stacktrace. Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report / Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants