Thank you for visiting the Rackspace Community
The Community is live! Post new content or topics so our teams can assist.

Please contact your support team if you have a question or need assistance for any Rackspace products, services, or articles.

.Net integration issue (openstack.net)

This question is answered.

Hello!

Our solutions is integrated with Rackspace Cloud FileStorage via openstack.net (from nuget). Sometimes (about once a month) we catch many "Chunked encoding upload is not supported on the HTTP/1.0 protocol" errors within a short period of time. Usually it continues for about half an hour or hour. Then, without any action on our side, the problem dissapears. IIS restart also helps. Below is the exception stacktrace:

Target site: Void CheckProtocol(Boolean)
System.Net.ProtocolViolationException: Chunked encoding upload is not supported on the HTTP/1.0 protocol.
   at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at JSIStudios.SimpleRESTServices.Client.RestServiceBase.<>c__DisplayClass4.<Stream>b__3(HttpWebRequest req)
   at JSIStudios.SimpleRESTServices.Client.RestServiceBase.<>c__DisplayClass7.<ExecuteRequest>b__6()
   at JSIStudios.SimpleRESTServices.Client.RequestRetryLogic.Execute(Func`1 callback, IEnumerable`1 non200SuccessCodes, Int32 retryCount, Nullable`1 retryDelay)
   at JSIStudios.SimpleRESTServices.Client.RestServiceBase.ExecuteRequest(Uri url, HttpMethod method, Func`3 responseBuilderCallback, Dictionary`2 headers, Dictionary`2 queryStringParameters, RequestSettings settings, Func`2 executeCallback)
   at JSIStudios.SimpleRESTServices.Client.RestServiceBase.Stream(Uri url, HttpMethod method, Stream content, Int32 bufferSize, Int64 maxReadLength, Dictionary`2 headers, Dictionary`2 queryStringParameters, RequestSettings settings, Action`1 progressUpdated)
   at net.openstack.Providers.Rackspace.ProviderBase`1.StreamRESTRequest(CloudIdentity identity, Uri absoluteUri, HttpMethod method, Stream stream, Int32 chunkSize, Int64 maxReadLength, Dictionary`2 queryStringParameter, Dictionary`2 headers, Boolean isRetry, RequestSettings requestSettings, Action`1 progressUpdated)
   at net.openstack.Providers.Rackspace.CloudFilesProvider.CreateObject(String container, Stream stream, String objectName, String contentType, Int32 chunkSize, Dictionary`2 headers, String region, Action`1 progressUpdated, Boolean useInternalUrl, CloudIdentity identity)
   at DocumentStorageRackspaceStorage.StoreDocument(Byte[] document, Guid documentId) in DocumentStorageRackspaceStorage.cs:line 35
   at DocumentStorage.WebService.StorageService.StoreDocument(DocumentInfo documentInfo, Byte[] document)
   at SyncInvokeStoreDocument(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

How can we resolve this issue?

Verified Answer
  • Prior to the next release of the SDK, I recommend adding the following class to your project. Then, when you create a new instance of CloudFilesProvider, pass an instance of this class as the restService parameter.

    namespace Your.Namespace
    {
        using System;
        using System.Collections.Generic;
        using HttpMethod = JSIStudios.SimpleRESTServices.Client.HttpMethod;
        using HttpVersion = System.Net.HttpVersion;
        using JsonRestServices = JSIStudios.SimpleRESTServices.Client.Json.JsonRestServices;
        using ProtocolViolationException = System.Net.ProtocolViolationException;
        using RequestSettings = JSIStudios.SimpleRESTServices.Client.RequestSettings;
        using Response = JSIStudios.SimpleRESTServices.Client.Response;
        using ServicePoint = System.Net.ServicePoint;
        using ServicePointManager = System.Net.ServicePointManager;
        using Stream = System.IO.Stream;
        using Thread = System.Threading.Thread;
    
        public class ProtocolViolationHandlingJsonRestServices : JsonRestServices
        {
            public override Response Stream(Uri url, HttpMethod method, Stream content, int bufferSize, long maxReadLength, Dictionary<string, string> headers, Dictionary<string, string> queryStringParameters, RequestSettings settings, Action<long> progressUpdated)
            {
                try
                {
                    return base.Stream(url, method, content, bufferSize, maxReadLength, headers, queryStringParameters, settings, progressUpdated);
                }
                catch (ProtocolViolationException)
                {
                    ServicePoint servicePoint = ServicePointManager.FindServicePoint(url);
                    if (servicePoint.ProtocolVersion < HttpVersion.Version11)
                    {
                        // this is a workaround for issue #333
                        // https://github.com/openstacknetsdk/openstack.net/issues/333
                        // http://stackoverflow.com/a/22976809/138304
                        int maxIdleTime = servicePoint.MaxIdleTime;
                        servicePoint.MaxIdleTime = 0;
                        Thread.Sleep(1);
                        servicePoint.MaxIdleTime = maxIdleTime;
                    }
    
                    return base.Stream(url, method, content, bufferSize, maxReadLength, headers, queryStringParameters, settings, progressUpdated);
                }
            }
        }
    }
    
All Replies
  • You are encountering issue issue #333, which is fixed for the next release of the SDK. If you don't read all of the comments on that issue, I encourage you to read at least the comment which starts with "More information...", as it contains the essential background information for understanding what happened.

  • Sharwell, thank you for the quick reply! Please advise, which way is prefferable from your point of view:

    1) Manually update the dll, obtaining it from github with the custom fix (until an official version is released). How safe is it?

    2) Implement the workaround with endpoint (Reset the ServicePoint if a ProtocolViolationException occurs)?

  • Prior to the next release of the SDK, I recommend adding the following class to your project. Then, when you create a new instance of CloudFilesProvider, pass an instance of this class as the restService parameter.

    namespace Your.Namespace
    {
        using System;
        using System.Collections.Generic;
        using HttpMethod = JSIStudios.SimpleRESTServices.Client.HttpMethod;
        using HttpVersion = System.Net.HttpVersion;
        using JsonRestServices = JSIStudios.SimpleRESTServices.Client.Json.JsonRestServices;
        using ProtocolViolationException = System.Net.ProtocolViolationException;
        using RequestSettings = JSIStudios.SimpleRESTServices.Client.RequestSettings;
        using Response = JSIStudios.SimpleRESTServices.Client.Response;
        using ServicePoint = System.Net.ServicePoint;
        using ServicePointManager = System.Net.ServicePointManager;
        using Stream = System.IO.Stream;
        using Thread = System.Threading.Thread;
    
        public class ProtocolViolationHandlingJsonRestServices : JsonRestServices
        {
            public override Response Stream(Uri url, HttpMethod method, Stream content, int bufferSize, long maxReadLength, Dictionary<string, string> headers, Dictionary<string, string> queryStringParameters, RequestSettings settings, Action<long> progressUpdated)
            {
                try
                {
                    return base.Stream(url, method, content, bufferSize, maxReadLength, headers, queryStringParameters, settings, progressUpdated);
                }
                catch (ProtocolViolationException)
                {
                    ServicePoint servicePoint = ServicePointManager.FindServicePoint(url);
                    if (servicePoint.ProtocolVersion < HttpVersion.Version11)
                    {
                        // this is a workaround for issue #333
                        // https://github.com/openstacknetsdk/openstack.net/issues/333
                        // http://stackoverflow.com/a/22976809/138304
                        int maxIdleTime = servicePoint.MaxIdleTime;
                        servicePoint.MaxIdleTime = 0;
                        Thread.Sleep(1);
                        servicePoint.MaxIdleTime = maxIdleTime;
                    }
    
                    return base.Stream(url, method, content, bufferSize, maxReadLength, headers, queryStringParameters, settings, progressUpdated);
                }
            }
        }
    }
    
  • Thanks a lot! Will follow this variant.