7

When using the AmazonS3 object for the first time after the application starts, there is a large delay of approx 14 seconds. This large time delay is not present for all subsequent calls.

I have encountered this exact delay issue before with other HTTP related classes and it is caused when the class in question tries to determine the local machine's proxy settings and whether to use them or not.

To stop this from happening with WebClient, you set WebClient.Proxy = null; and it doesn't try to auto detect the proxy settings, but I cannot figure out how to disable the proxy detection functionality of the AmazonS3 object.

I have specifically tried setting the ProxyHost to null:

_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey, new AmazonS3Config { ProxyHost = null });

Which didn't work. We are currently using the Amazon .NET SDK 'v1.3.17.0'.

Is there a way to turn off the proxy detection?

InvertedAcceleration
  • 10,695
  • 9
  • 46
  • 71

1 Answers1

6

Good question - I haven't tried it myself and only analyzed the code, but the AmazonS3Config Class uses a private method configureWebRequest(), which in turn relies on the WebRequest Class to handle the actual HTTP connection. Now, WebRequest has a WebRequest.DefaultWebProxy Property , which is public static (i.e. you can set this within your application before calling CreateAmazonS3Client(()) :

The DefaultWebProxy property gets or sets the global proxy. The DefaultWebProxy property determines the default proxy that all WebRequest instances use if the request supports proxies and no proxy is set explicitly using the Proxy property. [emphasis mine]

The proxy auto detection you are experiencing is supposedly induced by the respective IE behavior:

The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file, the current user's Internet Explorer (IE) proxy settings are used.

Consequently I'd hope that this can be disabled in a similar way as for the WebClient.Proxy Property you mentioned, albeit on the class level, as indeed strongly suggested by the last paragraph:

If the DefaultWebProxy property is set to null, all subsequent instances of the WebRequest class created by the Create or CreateDefault methods do not have a proxy. [emphasis mine]


Added by blexandre

sample code from this answer would be

System.Net.WebRequest.DefaultWebProxy = null;
_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey);

Note that this will disable the proxy for every web request, _client is created using it, so it is safe to do this, but be careful if you might have more requests pending from the WebRequest class

balexandre
  • 73,608
  • 45
  • 233
  • 342
Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • 1
    Thanks for the reply! I appreciate you taking the time to dig through the code. It really helps to know what technique the SDK is using under the hood. I have also posted this question on the Amazon .NET SDK developer forum, if I get any extra information I will post it here. Given the info you've provided, if the SDK can't currently turn off the proxy detection, it would appear to be a trivial change for them to make given they are using the `WebRequest` class for the HTTP requests. +1 – InvertedAcceleration Jan 24 '12 at 09:48
  • 1
    @InvertedAcceleration - `WebRequest.DefaultWebProxy` is a *public static* property, thus you should actually be able to configure it yourself within your application without any changes to the SDK (this is different from the WebClient.Proxy design indeed). I've emphasized this in the answer now, sorry for being misleading! – Steffen Opel Jan 24 '12 at 10:24
  • 1
    Awesome, that works perfectly! Thanks again! Wish I could +2 as well as accepting as the emphasis makes it really clear now (sorry I missed it in the initial answer!) :) – InvertedAcceleration Jan 24 '12 at 12:21
  • BTW, if you interested here is the link to me cross posting your answer on the Amazon .NET Developer Forum: https://forums.aws.amazon.com/thread.jspa?threadID=85527&tstart=0. – InvertedAcceleration Jan 24 '12 at 12:39
  • Thanks for answering the AWS forum question as well by linking over here, much appreciated! And a great and especially concise summary btw. - I'll try to learn from your example ;) – Steffen Opel Jan 24 '12 at 18:46