From 324daf60bfc4cc566aed106cc04c1e07df24a57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20S=C3=B8rensen-Boll?= Date: Wed, 24 Mar 2021 20:22:39 +0100 Subject: [PATCH 1/3] Changed AsyncWaitHandle.WaitOne 'exitContext' to true. Allowing, if in a synchronized context, to exit the synchronization before the wait. "The exitContext parameter has no effect unless the WaitOne method is called from inside a nondefault managed context. This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain." https://docs.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitone?view=netframework-3.5 --- src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs index 8f46102b..6499ae18 100644 --- a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs +++ b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs @@ -862,7 +862,9 @@ namespace dk.gov.oiosi.security.revocation.ocsp { AsyncOcspCall asyncOcspCall = new AsyncOcspCall(this.RevocationResponse); IAsyncResult asyncResult = asyncOcspCall.BeginInvoke(certificate, null, null); - bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(Utilities.TimeSpanInMilliseconds(TimeSpan.FromMilliseconds(_configuration.DefaultTimeoutMsec)), false); + //exitContext set to true: MSDOC: + //true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. + bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(_configuration.DefaultTimeoutMsec, true); if (ocspRepliedInTime) { // okay, the operation has finish. -- GitLab From 125e18e9a3db040c9d0a9c7864c69fd4efbfaff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20S=C3=B8rensen-Boll?= Date: Wed, 24 Mar 2021 21:52:51 +0100 Subject: [PATCH 2/3] Revert "Changed AsyncWaitHandle.WaitOne 'exitContext' to true. Allowing, if in a synchronized context, to exit the synchronization before the wait." This reverts commit 324daf60bfc4cc566aed106cc04c1e07df24a57a. --- src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs index 6499ae18..8f46102b 100644 --- a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs +++ b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs @@ -862,9 +862,7 @@ namespace dk.gov.oiosi.security.revocation.ocsp { AsyncOcspCall asyncOcspCall = new AsyncOcspCall(this.RevocationResponse); IAsyncResult asyncResult = asyncOcspCall.BeginInvoke(certificate, null, null); - //exitContext set to true: MSDOC: - //true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. - bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(_configuration.DefaultTimeoutMsec, true); + bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(Utilities.TimeSpanInMilliseconds(TimeSpan.FromMilliseconds(_configuration.DefaultTimeoutMsec)), false); if (ocspRepliedInTime) { // okay, the operation has finish. -- GitLab From 0c662ee3787163f291dedf815d1762568c99b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20S=C3=B8rensen-Boll?= Date: Wed, 24 Mar 2021 21:59:27 +0100 Subject: [PATCH 3/3] Changed AsyncWaitHandle.WaitOne 'exitContext' to true. Allowing, if in a synchronized context, to exit the synchronization before the wait. This fixes the failure in the unit test due to its synchronous context. This change will not have influence on other functionalities, due the nature of exitContext. "The exitContext parameter has no effect unless the WaitOne method is called from inside a nondefault managed context. This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain." https://docs.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitone?view=netframework-3.5 --- src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs index 8f46102b..51348d70 100644 --- a/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs +++ b/src/dk.gov.oiosi/security/revocation/ocsp/OcspLookup.cs @@ -862,7 +862,7 @@ namespace dk.gov.oiosi.security.revocation.ocsp { AsyncOcspCall asyncOcspCall = new AsyncOcspCall(this.RevocationResponse); IAsyncResult asyncResult = asyncOcspCall.BeginInvoke(certificate, null, null); - bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(Utilities.TimeSpanInMilliseconds(TimeSpan.FromMilliseconds(_configuration.DefaultTimeoutMsec)), false); + bool ocspRepliedInTime = asyncResult.AsyncWaitHandle.WaitOne(_configuration.DefaultTimeoutMsec, true); if (ocspRepliedInTime) { // okay, the operation has finish. -- GitLab