Make sure that sockets which couldn't be opened aren't handled as active connections, in which case they wouldn't be closed.

Please test this and report any problems (connections that stay open for a very long time according to http://<your_yacy_peed>/Connections_p.html to http://forum.yacy-websuche.de/viewtopic.php?f=5&t=386

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4132 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
fuchsi 18 years ago
parent 03c5b4ad68
commit 1eba408d2f

@ -227,8 +227,9 @@ public final class httpc {
String outgoingByteCountAccounting
) throws IOException {
// TODO method can be removed completely when no more CLOSE_WAIT connections appear.
// remove old connections
checkIdleConnections();
//checkIdleConnections();
// register new connection
this.hashIndex = objCounter;
@ -390,12 +391,8 @@ public final class httpc {
// trying to establish a connection to the address
this.initTime = System.currentTimeMillis();
this.socket.connect(address, timeout);
// setting socket timeout and keep alive behaviour
this.socket.setSoTimeout(timeout); // waiting time for read
//socket.setSoLinger(true, timeout);
this.socket.setKeepAlive(false); //
this.socket.connect(address, timeout);
if (incomingByteCountAccounting != null) {
this.clientInputByteCount = new httpdByteCountInputStream(this.socket.getInputStream(),incomingByteCountAccounting);
@ -418,6 +415,14 @@ public final class httpc {
}
this.socket = null;
throw new IOException("unknown host: " + server);
} catch (IOException e) {
// There was an error while connecting the socket, probably a SocketTimeoutException
// we have to close the httpc, otherwise it would stay in activeConnections forever
serverLog.logFine("HTTPC", "Couldn't open socket to: " + this.adressed_host + ":" + this.adressed_port);
close();
// TODO do we need to hand it over to the caller?
throw e;
}
}
@ -429,6 +434,7 @@ public final class httpc {
return (this.clientOutputByteCount == null)?0:this.clientOutputByteCount.getCount();
}
// TODO remove when it's sure that the CLOSE_WAIT problem was solved.
public static int checkIdleConnections() {
// try to find and close all connections that did not find a target server and are idle waiting for a server socket
@ -508,7 +514,7 @@ public final class httpc {
public void close() {
synchronized (activeConnections) {activeConnections.remove(this);}
//System.out.println("*** DEBUG close httpc: " + activeConnections.size() + " connections online");
System.out.println("*** DEBUG close httpc: " + activeConnections.size() + " connections online");
if (this.clientInput != null) {
try {this.clientInput.close();} catch (Exception e) {}

Loading…
Cancel
Save