-
-
Notifications
You must be signed in to change notification settings - Fork 340
Fix empty string received by .NET 8 users on Linux on userName #199
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 empty string received by .NET 8 users on Linux on userName #199
Conversation
5efe77f to
f86dff6
Compare
FreeAndNil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some hints
|
@FreeAndNil Thanks for the extra quick check of my draft! I will iterate on the suggestions and questions/stuff in description. What is the deadline for 3.0.3? |
|
There is no deadline yet. |
|
Adding some unit tests would be very nice. |
|
I will add the unit tests. |
|
Hi @gdziadkiewicz, trying to answer some of your questions.
Yes this would be really helpful. There is #106 and a github-actions branch from @rm5248 - I didn't find the time yet to take a closer look.
I think we can skip net6 (support ends in 3 weeks) and mono on windows (I don't think many users will do this).
Yes. https://github.com/dotnet/runtime/tree/main/src/libraries/System.Security.Principal.Windows/src
It should work on all platforms, but it seems to give different results in web applications.
Yes. Same as net471. https://github.com/mono/mono/blob/main/mcs/class/corlib/System.Security.Principal/WindowsIdentity.cs
Do you mean switching from net462 to net471 or adding a comment in the code? Caching of the username seems not to be necessary. I get around 500 ms for 10.000 calls. |
f86dff6 to
f082df9
Compare
|
My plan was to find the answers alone, without using your time :D Thank you for the research!
Current code guarding the code is |
|
I added the unit test and tested on Windows. |
|
@FreeAndNil I'm wondering about two parts of the code. One is the: catch
{
return null;
}Should it really be the only place that doesn't fail back to and the second is the first if utilizing the flag: if (_platformDoesNotSupportWindowsIdentity)
{
// we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName
// and it's highly unlikely that will change
return Environment.UserName;
}It is the only piece of code outside of the try block. It would be highly unfortunate to get an unhandled exception from it(based on impl details |
Good point, you can adjust this. |
@fluffynuts you did the last meaningful change at this line in e137855 WDYT?
We could catch errors and return NOTAVAILABLE. BTW I recently activated the .net analyzers in #201 and changed all the catch-alls, so please merge master. |
b44a9a8 to
6c9afd2
Compare
|
Hi, I implemented the suggestions, extended the try, and refreshed the branch with Master. It's good to be reviewed now :) |
|
LGTM, thanks a lot. |
Background
While working on getting log4net.Ext.Json package to work with log4net 3 I noticed a regression. With log4net 2.0.10 the test checking if the user name is as expected worked both during local run on my Windows machine and on the CI Linux agent used by Gitlab. After upgrading log4net to version 3.0.1 it stopped working on the CI and started reporting that the user name is an empty string.
Passing:
https://gitlab.com/gdziadkiewicz/log4net.Ext.Json/-/jobs/7522362244
Failing:
https://gitlab.com/gdziadkiewicz/log4net.Ext.Json/-/jobs/8094529032#L172
Testing
It would be great to be able to run tests for log4net on all combinations of frameworks and OSes automatically (would you be interested in someone getting started work on it?).
In the meantime it draws as important for me to test (not sure about expected results yet):
Questions to answer before finalizing the change
Environment.Userimplemented on different platforms? Does it change? Is it expensive? Would caching make sense?