{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/25477","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/25477/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/25477/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/25477/events","html_url":"https://github.com/dotnet/corefx/issues/25477","id":276505085,"number":25477,"title":"AsyncLocal.OnValueChanged seems to be called with a stale change, crashing the process","user":{"login":"lakeman","id":590814,"avatar_url":"https://avatars2.githubusercontent.com/u/590814?v=4","gravatar_id":"","url":"https://api.github.com/users/lakeman","html_url":"https://github.com/lakeman","followers_url":"https://api.github.com/users/lakeman/followers","following_url":"https://api.github.com/users/lakeman/following{/other_user}","gists_url":"https://api.github.com/users/lakeman/gists{/gist_id}","starred_url":"https://api.github.com/users/lakeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lakeman/subscriptions","organizations_url":"https://api.github.com/users/lakeman/orgs","repos_url":"https://api.github.com/users/lakeman/repos","events_url":"https://api.github.com/users/lakeman/events{/privacy}","received_events_url":"https://api.github.com/users/lakeman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-11-24T03:15:56Z","updated_at":"2017-11-24T14:11:34Z","closed_at":null,"author_association":"NONE","body":"I've attempted to write a middleware service to use WindowsIdentity.RunImpersonated, Wait()-ing for the next handler to return. \r\n\r\nHowever I've seen that WindowsIdentity.CurrentImpersonatedTokenChanged is called a final time after my middleware finishes, with a closed but valid windows token. This leads to Environment.FailFast being called in ExecutionContext.OnContextChanged, which is logging the stack trace from OnContextChanged, but isn't logging the details of the exception that was caught.\r\n\r\nThere seem to be a number of problems here;\r\n- We need an async version of RunImpersonated (#24977)\r\n- WindowsIdentity.CurrentImpersonatedTokenChanged should check for closed tokens\r\n- Environment.FailFast should log the exception details (https://github.com/dotnet/coreclr/issues/15203)\r\n- AsyncLocal.OnValueChanged seems to be called with a stale change after an async task has completed.\r\n\r\nIn the meantime, I've worked around the problem by calling advapi32.dll ImpersonateLoggedOnUser / RevertToSelf directly from an AsyncLocal change handler, essentially implementing an async version of RunImpersonated myself.\r\n\r\nEDIT by @ViktorHofer: added issue link for failfast."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/346836952","html_url":"https://github.com/dotnet/corefx/issues/25477#issuecomment-346836952","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/25477","id":346836952,"user":{"login":"lakeman","id":590814,"avatar_url":"https://avatars2.githubusercontent.com/u/590814?v=4","gravatar_id":"","url":"https://api.github.com/users/lakeman","html_url":"https://github.com/lakeman","followers_url":"https://api.github.com/users/lakeman/followers","following_url":"https://api.github.com/users/lakeman/following{/other_user}","gists_url":"https://api.github.com/users/lakeman/gists{/gist_id}","starred_url":"https://api.github.com/users/lakeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lakeman/subscriptions","organizations_url":"https://api.github.com/users/lakeman/orgs","repos_url":"https://api.github.com/users/lakeman/repos","events_url":"https://api.github.com/users/lakeman/events{/privacy}","received_events_url":"https://api.github.com/users/lakeman/received_events","type":"User","site_admin":false},"created_at":"2017-11-24T14:11:34Z","updated_at":"2017-11-24T14:11:34Z","author_association":"NONE","body":"Here's my version of an async windows impersonation middleware, that I wrote to work around this issue; \r\nhttps://gist.github.com/lakeman/26af3a6d047d3de84c710711781ea709\r\n\r\nIn my testing, TokenChanged is called *after* setting the value to null, with a non-null closed token."}}
{"actor":{"display_login":"lakeman"}}