brsanthu / proxy-vole

Automatically exported from code.google.com/p/proxy-vole

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StackOverflowError while trying to read Url based Pac Script

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. Define URL Based Pac Script for proxy connection
2. Use JRE 1.7.0_b05
3. Attempt to connect via proxy to internet

What is the expected output? What do you see instead?
Expected is to connect to internet, however, it gives a StackOverflowError. The 
error is due to an infinite loop of trying to detect proxy server while 
attempting to download the Pac script content.

What version of the product are you using? On what operating system?
Using the latest version 20120727.

Here is the code used:

         ProxySearch proxySearch = new ProxySearch();
         if(PlatformUtil.getCurrentPlattform() == Platform.WIN)
         {
            proxySearch.addStrategy(Strategy.IE);
            proxySearch.addStrategy(Strategy.FIREFOX);
            proxySearch.addStrategy(Strategy.JAVA);
          }
         else if (PlatformUtil.getCurrentPlattform() == Platform.LINUX)
         {
            proxySearch.addStrategy(Strategy.GNOME);
            proxySearch.addStrategy(Strategy.KDE);
            proxySearch.addStrategy(Strategy.FIREFOX);
         }
         else
         {
            proxySearch.addStrategy(Strategy.OS_DEFAULT);
         }
         //proxySearch.addStrategy(Strategy.OS_DEFAULT);
         ProxySelector myProxySelector = proxySearch.getProxySelector();
         ProxySelector.setDefault(myProxySelector);

         URI salesforceUri = new URI("https://cg.na6.visual.force.com/services/Soap/u/20.0");
         List<Proxy> proxies = ProxySelector.getDefault().select(salesforceUri);

Here is the stack trace:
Java Plug-in 10.5.1.255
Using JRE version 1.7.0_05-b06 Java HotSpot(TM) Client VM
User home directory = C:\Users\phe007
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
Exception in thread "AWT-EventQueue-2" java.lang.StackOverflowError
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.<init>(Unknown Source)
    at sun.net.www.protocol.http.Handler.openConnection(Unknown Source)
    at java.net.URL.openConnection(Unknown Source)
    at com.btr.proxy.selector.pac.UrlPacScriptSource.downloadPacContent(UrlPacScriptSource.java:108)
    at com.btr.proxy.selector.pac.UrlPacScriptSource.getScriptContent(UrlPacScriptSource.java:52)
    at com.btr.proxy.selector.pac.JavaxPacScriptParser.evaluate(JavaxPacScriptParser.java:113)
    at com.btr.proxy.selector.pac.PacProxySelector.findProxy(PacProxySelector.java:105)
    at com.btr.proxy.selector.pac.PacProxySelector.select(PacProxySelector.java:88)
    at com.btr.proxy.selector.misc.BufferedProxySelector.select(BufferedProxySelector.java:84)
    at com.btr.proxy.selector.misc.ProxyListFallbackSelector.select(ProxyListFallbackSelector.java:71)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at com.btr.proxy.selector.pac.UrlPacScriptSource.downloadPacContent(UrlPacScriptSource.java:112)
    at com.btr.proxy.selector.pac.UrlPacScriptSource.getScriptContent(UrlPacScriptSource.java:52)
    at com.btr.proxy.selector.pac.JavaxPacScriptParser.evaluate(JavaxPacScriptParser.java:113)
    at com.btr.proxy.selector.pac.PacProxySelector.findProxy(PacProxySelector.java:105)
    at com.btr.proxy.selector.pac.PacProxySelector.select(PacProxySelector.java:88)
    at com.btr.proxy.selector.misc.BufferedProxySelector.select(BufferedProxySelector.java:84)
    at com.btr.proxy.selector.misc.ProxyListFallbackSelector.select(ProxyListFallbackSelector.java:71)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

Original issue reported on code.google.com by bulent.d...@gmail.com on 5 Aug 2012 at 9:44

I also get the same stacktrace using 2011-11-02
it looks like it loops at: getResponseCode()
which at a later stage opens a socket connection, which uses the 
(proxy-vol)ProxySelector, which then tries to tries download the PAC script 
again... then we are in the infinite loop...

My java env is: 
C:\>java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03)
Java HotSpot(TM) Client VM (build 20.8-b03, mixed mode, sharing)

Original comment by goran.sc...@gmail.com on 14 Aug 2012 at 11:01

If I download the PAC file from the server and keep it locally 
(file://C:/DUMMY.pac)
Then it work OK!


Original comment by goran.sc...@gmail.com on 14 Aug 2012 at 1:22

The idea is to keep the PAC file central in the network. I don't think we can 
say that it is a viable option.

Original comment by bulent.d...@gmail.com on 14 Aug 2012 at 1:39

Hi,
I will have a look at this. 
This is a bug in Java. When I download the pac file from the server in proxy 
vole i specify that I do not want to use any proxy. See:

http://code.google.com/p/proxy-vole/source/browse/trunk/proxy_vole/src/com/btr/p
roxy/selector/pac/UrlPacScriptSource.java#108 

This is to prevent this. But Java is ignoring this and still tries to find a 
proxy.
I will have a look at this soon. There is somewhere a workaround for this bug 
but I have to check it and then integrate this.

The idea is to check if the URL is the one that is used to download the PAC 
file and if it is the same then always return DIRECT to prevent the recursive 
call.

Thanks guys for reporting this. I will try to provide an working version soon.

Have fun,
- Rossi


Original comment by rosstaus...@googlemail.com on 14 Aug 2012 at 2:28

  • Changed state: Accepted
Sorry this did not work.
I used eclipse to trace it, and attached a screendump with a "inspect" on the 
variable ps.
ps is ProxyListFallbackSelector, with delegate=BufferedProxySelector, which 
finaly is delegated to PacProxySelector

So the instanceof check has to loop/drilldown on the "ps" variable to check for 
PacProxySelector.
Or some other solution

/Goran

PS. I also attached my test file ProxyTest.java

Original comment by goran.sc...@gmail.com on 6 Sep 2012 at 5:55

Attachments:

Hello Goran,
You are right it does not work at all because of the buffering (which nests the 
selectors). I tested it without the buffering only in a test case.

I will to a next try to solve this bloody bug today. I will change the 
setEnabled and isEnabled methods on the PacProxySelector to "static" and invoke 
them directly without the "instance of" test.

This is then not nice but hopefully should then finally work.


Original comment by rosstaus...@googlemail.com on 11 Sep 2012 at 6:32

  • Changed state: Accepted
Sorry... but downloading the PAC file and keeping it locally, was not an idea 
for a "work around"... it was just a info message that it's the download of the 
PAC file that caused the problem and not the PAC file syntax or similar.

But Rossi understud the issue and have a workaround "in progress", by looking 
at hes reply...

Thanx

Original comment by goran.sc...@gmail.com on 14 Aug 2012 at 9:25

Hi Rossi,

Did you get any further with this issue? I want to get this to work but if you 
found a dead-end, I don't want to waste time.

Thanks

Original comment by bulent.d...@gmail.com on 27 Aug 2012 at 11:37

Hello,
I was on holidays Sorry for the late reply. 
Finally I found the time to look into this. I have to admit that I do not 
exactly know why the workaround that was already in the code did not work. I 
cannot reproduce the issue here.

I decided to implement a more reliable way of working around the Java bug. This 
is in the new release: proxy-vole 20120905

Please download that one and test it. I'm quite confident that this should 
solve the problem.

Have fun,
- Rossi

Original comment by rosstaus...@googlemail.com on 5 Sep 2012 at 9:54

  • Changed state: Fixed
Thanks Ill test it soon :)

Original comment by goran.sc...@gmail.com on 5 Sep 2012 at 10:11

Hi again,
I have now commited a next version of my fix that uses a static flag to prevent 
the recursion.
I have checked this in and released a new version that contains this fix.
(proxy-vole-20120920)

Hopefully this bug is now really gone.

Have fun,
- Rossi

Original comment by rosstaus...@googlemail.com on 20 Sep 2012 at 6:49

  • Changed state: Fixed