Skip to content

File target: Handle UnauthorizedAccessException for multi-process mutexes (e.g. Xamarin and UWP)#3079

Merged
304NotModified merged 3 commits intodevfrom
detect-mutex2
Jan 28, 2019
Merged

File target: Handle UnauthorizedAccessException for multi-process mutexes (e.g. Xamarin and UWP)#3079
304NotModified merged 3 commits intodevfrom
detect-mutex2

Conversation

@304NotModified
Copy link
Copy Markdown
Member

detect creating Mutex also runtime.

alternative solution for #3048

See #2742 and #2824 and #2925 and #3059

supersedes #3063

@304NotModified
Copy link
Copy Markdown
Member Author

@snakefoot your input please :)

@snakefoot
Copy link
Copy Markdown
Contributor

So when people configure KeepFileOpen on limited NetCore-platforms then they will continue to have KeepFileOpen=false. Think this is very confusing, and still prefer to have ConcurrentWrites = false by default on NetCore-platforms, instead of all this guess-magic.

Still don't like the testing with exceptions. Also you need to catch a lot more. See also

if (ex is SecurityException || ex is UnauthorizedAccessException || ex is NotSupportedException || ex is NotImplementedException || ex is PlatformNotSupportedException)

@304NotModified
Copy link
Copy Markdown
Member Author

So when people configure KeepFileOpen on limited NetCore-platforms then they will continue to have KeepFileOpen=false. Think this is very confusing, and still prefer to have ConcurrentWrites = false by default on NetCore-platforms, instead of all this guess-magic.

I tried to not change the current behavior (the fallback when there is no mutex), but only change the detection, which wasn't good enough.

If the fallback is not good, IMO that's another issue and maybe more for NLog 5.

Still don't like the testing with exceptions. Also you need to catch a lot more. See also

if (ex is SecurityException || ex is UnauthorizedAccessException || ex is NotSupportedException || ex is NotImplementedException || ex is PlatformNotSupportedException)

will fix that

…exes (e.g. Xamarin and UPW)

detect creating Mutex also runtime.
@304NotModified 304NotModified added this to the 4.6 milestone Jan 13, 2019
@snakefoot
Copy link
Copy Markdown
Contributor

Please make CreateSharableMutex() return null instead of creating a dummy Mutex-object.

And places where null is not acceptable (Ex. MutexMultiProcessFileAppender) then throw exception.

@304NotModified
Copy link
Copy Markdown
Member Author

Please make CreateSharableMutex() return null instead of creating a dummy Mutex-object.

that's existing code. Just moved around.

@snakefoot
Copy link
Copy Markdown
Contributor

snakefoot commented Jan 13, 2019

Yes but now you have made the support-detection more advanced, and the fallback was invalid, and now the fallback is exercised even more.

@304NotModified
Copy link
Copy Markdown
Member Author

Fair enough, will check that

@304NotModified 304NotModified self-assigned this Jan 13, 2019
@snakefoot
Copy link
Copy Markdown
Contributor

Btw. Title of PR should be UWP (and not UPW)

@304NotModified 304NotModified changed the title File target: Handle UnauthorizedAccessException for multi-process mutexes (e.g. Xamarin and UPW) File target: Handle UnauthorizedAccessException for multi-process mutexes (e.g. Xamarin and UWP) Jan 13, 2019
@304NotModified
Copy link
Copy Markdown
Member Author

WUPS!

@304NotModified
Copy link
Copy Markdown
Member Author

@snakefoot please review, thanks!

@304NotModified 304NotModified added enhancement Improvement on existing feature Xamarin labels Jan 25, 2019
exception on creating mutex but not supported
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2019

Codecov Report

Merging #3079 into dev will increase coverage by 1%.
The diff coverage is 69%.

@@           Coverage Diff           @@
##             dev   #3079     +/-   ##
=======================================
+ Coverage     80%     80%     +1%     
=======================================
  Files        349     349             
  Lines      27519   28685   +1166     
  Branches    3653    3986    +333     
=======================================
+ Hits       21903   22977   +1074     
- Misses      4567    4634     +67     
- Partials    1049    1074     +25

Comment thread src/NLog/Internal/FileAppenders/BaseMutexFileAppender.cs Outdated
Comment thread src/NLog/Internal/PlatformDetector.cs
Comment thread src/NLog/Targets/FileTarget.cs Outdated
Comment thread src/NLog/Targets/FileTarget.cs Outdated
@304NotModified
Copy link
Copy Markdown
Member Author

@snakefoot thanks for your suggestions. Those are applied now. Please let me know if this is ready to merge :)

@snakefoot
Copy link
Copy Markdown
Contributor

snakefoot commented Jan 28, 2019

Looks good now. Still prefer just having global-mutex disabled by default for NetCore. Better performance and better compatibility. Maybe for NLog 5.0 ?

@304NotModified 304NotModified merged commit 6cab40b into dev Jan 28, 2019
@304NotModified 304NotModified deleted the detect-mutex2 branch January 28, 2019 09:49
@304NotModified
Copy link
Copy Markdown
Member Author

Looks good now. Still prefer just having global-mutex disabled by default for NetCore. Better performance and better compatibility. Maybe for NLog 5.0 ?

I think that's OK, but we have to double check the pro and cons for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement on existing feature file-target platform support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants