Hi,
it seems to me that the followig method in AbstractOpenWebService
has some leak-like issues (see end of the mail).
Basically, we do have the opening of a new connection, that is not passed
around to anything, and is never disconnected. I guess it'll be during
garbage
collection and finalization, but it seems to be it should be
disconnected asap,
maybe linking somehow the disconnection to the end of the input stream.
One more thing that scares me is that the typical code to read an image
from a GetMap request is more or less along the lines of:
GetMapRequest request = wms.createGetMapRequest();
request.addLayer(layer);
...
GetMapResponse response = wms.issueRequest(request);
BufferedImage image = ImageIO.read(response.getInputStream());
and there's not clear cut way to "close" the response... I noticed
that in a stress test against geoserver I'm writing, adding:
response.getInputStream().close();
after the above allows geoserver to handle much more requests before
bombing with an OOM.
So my proposal would be to have the connection and streams handled
in the requests objects and have an explicit close() method that allows
to clean up both the stream and the connection.
Let me know what you think
Cheers
Andrea Aime
-------------------------------------------------------------------------------------------
protected Response internalIssueRequest( Request request ) throws
IOException, ServiceException {
URL finalURL = request.getFinalURL();
HttpURLConnection connection = (HttpURLConnection)
finalURL.openConnection();
connection.addRequestProperty("Accept-Encoding", "gzip");
if (request.requiresPost()) {
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-type",
request.getPostContentType());
OutputStream outputStream = connection.getOutputStream();
if (LOGGER.isLoggable(Level.FINE)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
request.performPostOutput(out);
InputStream in = new
ByteArrayInputStream(out.toByteArray());
BufferedReader reader = new BufferedReader(new
InputStreamReader(in));
PrintStream stream = new PrintStream(outputStream);
String postText = "";
while (reader.ready()) {
String input = reader.readLine();
postText = postText + input;
stream.println(input);
}
LOGGER.fine(postText);
System.out.println(postText);
out.close();
in.close();
} else {
request.performPostOutput(outputStream);
}
outputStream.flush();
outputStream.close();
} else {
connection.setRequestMethod("GET");
}
InputStream inputStream = connection.getInputStream();
if (connection.getContentEncoding() != null &&
connection.getContentEncoding().indexOf("gzip") != -1) { //$NON-NLS-1$
inputStream = new GZIPInputStream(inputStream);
}
String contentType = connection.getContentType();
return request.createResponse(contentType, inputStream);
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel