Skip to content

Commit

Permalink
Fixed a race condition where data would remain in the HTTP proxy buff…
Browse files Browse the repository at this point in the history
…er upon an HTTP exception, so connections would remain in WAIT mode at the OS level for quite a while. We now attenpt to empty the input stream buffer just in case there is still something stuck in it.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@263 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Jul 10, 2009
1 parent 19e1f76 commit d8f7cb5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public XmlaOlap4jHttpProxy(XmlaOlap4jDriver driver) {
public byte[] getResponse(URL url, String request)
throws XmlaOlap4jProxyException
{
URLConnection urlConnection = null;
try {
// Open connection to manipulate the properties
URLConnection urlConnection = url.openConnection();
urlConnection = url.openConnection();
urlConnection.setDoOutput(true);

// Set headers
Expand Down Expand Up @@ -102,6 +103,26 @@ public byte[] getResponse(URL url, String request)
// All exceptions should be trapped here.
// The response will only be available here anyways.
} catch (Exception e) {
// In order to prevent the JDK from keeping this connection
// in WAIT mode, we need to empty the error stream cache.
try {
final int espCode =
((HttpURLConnection)urlConnection).getResponseCode();
InputStream errorStream =
((HttpURLConnection)urlConnection).getErrorStream();

final ByteArrayOutputStream baos =
new ByteArrayOutputStream();
final byte[] buf = new byte[1024];
int count;
while ((count = errorStream.read(buf)) > 0) {
baos.write(buf, 0, count);
}
errorStream.close();
baos.close();
} catch(IOException ex) {
// Well, we tried. No point notifying the user here.
}
throw new XmlaOlap4jProxyException(
"This proxy encountered an exception while processing the "
+ "query.",
Expand Down

0 comments on commit d8f7cb5

Please sign in to comment.