I'm working on resolving this bug:
https://github.com/openstacknetsdk/openstack.net/issues/333
The issue involves a ProtocolViolationException
with the following message:
Chunked encoding upload is not supported on the HTTP/1.0 protocol.
I found that I am able to reliably reproduce the issue my making a web request that produces a 502 response code, followed by the call to use a POST request with chunked encoding. I traced this back to the ServicePoint.HttpBehaviour
property having the value HttpBehaviour.HTTP10
following the 502 response.
I was able to resolve the issue using the following hack (in the catch
block). This code "hides" the ServicePoint
instance created by the failed request from the ServicePointManager
, forcing it to create a new ServicePoint
for the next request.
public void TestProtocolViolation()
{
try
{
TestTempUrlWithSpecialCharactersInObjectName();
}
catch (WebException ex)
{
ServicePoint servicePoint = ServicePointManager.FindServicePoint(ex.Response.ResponseUri);
FieldInfo table = typeof(ServicePointManager).GetField("s_ServicePointTable", BindingFlags.Static | BindingFlags.NonPublic);
WeakReference weakReference = (WeakReference)((Hashtable)table.GetValue(null))[servicePoint.Address.GetLeftPart(UriPartial.Authority)];
if (weakReference != null)
weakReference.Target = null;
}
TestTempUrlExpired();
}
Questions:
- Why am I observing this behavior?
- What is a non-hacky way to resolve the issue?