Menu

#1002 StackOverflowError when getting too many redirects

Latest SVN
closed
None
5
2012-10-21
2009-12-16
Anonymous
No

Hi all,

If you have a web server which sends an HTTP/303 response each time you get to a particular url, then the WebClient is following that redirect indefinitely.
This occurs when there is a bug in a dynamic page and the server tries to redirect the client to a safe page which is also failing for any reason.
In that case because the error page is also failing, the client is again redirected to the error page, which redirects to the error page, etc.

I think you should introduce (or reused) the equivalent of the nbAllowedRedirections in case of the response code is HttpStatus.SC_SEE_OTHER so then it would stop the infinite redirection.

Here is the interesting part of the stack:


Caused by: java.lang.StackOverflowError
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:506)
at org.apache.commons.httpclient.HttpConnection.closeIfStale(HttpConnection.java:431)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.closeIfStale(MultiThreadedHttpConnectionManager.java:1313)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:97)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1430)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1482)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1482)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1482)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1482)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1482)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)

This also happen with the latest code built from this morning using svn trunk.

Cheers,
/Benoit

Discussion

  • Anonymous

    Anonymous - 2009-12-16

    Just realised that I've attached the wrong stack trace, that was with version 2.5 of html unit.

    Below is the stack trace corresponding to trunk:


    Caused by: java.lang.StackOverflowError
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
    at org.apache.commons.httpclient.HttpConnection.isStale(HttpConnection.java:506)
    at org.apache.commons.httpclient.HttpConnection.closeIfStale(HttpConnection.java:431)
    at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.closeIfStale(MultiThreadedHttpConnectionManager.java:1313)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:101)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1402)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1336)

    Cheers,
    /Benoit

     

    Last edit: Anonymous 2013-11-20
  • Daniel Gredler

    Daniel Gredler - 2010-01-03

    Fixed in SVN (I think); let us know if you still have trouble.

     

Log in to post a comment.