Update of /cvsroot/freenet/freenet/src/freenet/interfaces
In directory sc8-pr-cvs1:/tmp/cvs-serv21267/src/freenet/interfaces
Modified Files:
BaseLocalNIOInterface.java LocalNIOInterface.java
Log Message:
6170:
Fix synchronization on wrong object for runningConnections in LocalNIOInterface. Bug
could conceivably have caused web interface to freeze.
Check if we need to reenable web interface if we runningConnections-- in
ConnectionShell finalizer.
Logging.
Index: BaseLocalNIOInterface.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/interfaces/BaseLocalNIOInterface.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BaseLocalNIOInterface.java 23 Jul 2003 14:19:51 -0000 1.4
+++ BaseLocalNIOInterface.java 5 Sep 2003 02:00:46 -0000 1.5
@@ -16,6 +16,7 @@
public abstract class BaseLocalNIOInterface extends NIOInterface {
protected int[][] allowedHosts;
+ boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
private static final int intAddress(String addr) {
try {
@@ -27,16 +28,17 @@
private static final int intAddress(InetAddress addr) {
boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
- if(logDEBUG) Core.logger.log(LocalInterface.class, "intAddress("+
+ if(logDEBUG) Core.logger.log(LocalNIOInterface.class, "intAddress("+
addr.toString()+")", Logger.DEBUG);
byte[] b = addr.getAddress();
- if(logDEBUG) Core.logger.log(LocalInterface.class, "Address: "+(((int)b[0]) &
0xff) +
- "."+(((int)b[1]) & 0xff)+"."+(((int)b[2]) &
0xff)+"."+
+ if(logDEBUG) Core.logger.log(LocalNIOInterface.class, "Address: "+
+ (((int)b[0]) & 0xff) +"."+(((int)b[1]) & 0xff)+
+ "."+(((int)b[2]) & 0xff)+"."+
(((int)b[3]) & 0xff)+" ("+
b.length+")", Logger.DEBUG);
long x = ((((long)b[0]) & 0xff) << 24) + ((((int)b[1]) & 0xff) << 16) +
((((int)b[2]) & 0xff) << 8) + (((int)b[3]) & 0xff);
- if(logDEBUG) Core.logger.log(LocalInterface.class, "Returning "+
+ if(logDEBUG) Core.logger.log(LocalNIOInterface.class, "Returning "+
Fields.longToHex(x), Logger.DEBUG);
return (int) x;
}
@@ -55,7 +57,6 @@
return out;
}
- int runningConnections = 0; // number of connections running
int lowRunningConnections; // reenable interface when go below this
int highRunningConnections; // disable interface when go above this
@@ -113,7 +114,7 @@
allowedHosts = "0.0.0.0/0";
}
- if(Core.logger.shouldLog(Logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this, "New BaseLocalNIOInterface: "+listenAddr+
","+allowedHosts, Logger.DEBUG);
@@ -147,9 +148,10 @@
* @exception RejectedConnectionException Description of the Exception
*/
protected void dispatch(Connection conn) throws RejectedConnectionException {
+ logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
boolean allow = false;
Address ha = conn.getPeerAddress();
- if(Core.logger.shouldLog(Core.logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this,
"Dispatching connection on a BaseLocalNIOInterface from " +
ha.toString(), Core.logger.DEBUG);
@@ -168,7 +170,7 @@
int subnet = allowedHosts[i][0];
int maskbits = allowedHosts[i][1];
allow |= (mask(inta, maskbits) == subnet);
- if(Core.logger.shouldLog(Core.logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this, "Trying "+Fields.intToHex(subnet)+
":"+Fields.intToHex(maskbits)+" for "+
Fields.intToHex(inta), Core.logger.DEBUG);
@@ -177,7 +179,7 @@
if (allow) {
handleConnection(conn);
} else {
- if(Core.logger.shouldLog(Core.logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this, "Rejecting local connection",
Core.logger.DEBUG);
throw new RejectedConnectionException("host not allowed: " + ha);
Index: LocalNIOInterface.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/interfaces/LocalNIOInterface.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalNIOInterface.java 28 Jun 2003 16:10:22 -0000 1.3
+++ LocalNIOInterface.java 5 Sep 2003 02:00:46 -0000 1.4
@@ -148,14 +148,24 @@
protected void handleConnection(Connection conn) {
if(acceptingConnections) {
+ if(logDEBUG)
+ Core.logger.log(this, "Accepting connection immediately: "+
+ conn, Logger.DEBUG);
realHandleConnection(conn);
synchronized(oldConnections) {
+ int i=0;
while(!oldConnections.isEmpty() && acceptingConnections) {
+ if(logDEBUG)
+ Core.logger.log(this, "Handling old connection #"+i++,
+ Logger.DEBUG);
realHandleConnection((Connection)oldConnections.
removeFirst());
}
}
} else {
+ if(logDEBUG)
+ Core.logger.log(this, "Deferring connection "+conn,
+ Logger.DEBUG);
synchronized(oldConnections) {
int deleted = 0;
while(oldConnections.size() >= MAX_QUEUED_CONNECTIONS) {
@@ -166,6 +176,9 @@
Core.logger.log(this, "Dropped "+deleted+" old connections",
Logger.NORMAL);
oldConnections.addFirst(conn);
+ if(logDEBUG)
+ Core.logger.log(this, "Added "+conn+" - "+oldConnections.size()+
+ " connections queued", Logger.DEBUG);
}
}
}
@@ -173,11 +186,13 @@
protected void realHandleConnection(Connection conn) {
if(runner.needsThread()) {
Thread t = tf.getThread(new ConnectionShell(conn));
- Core.logger.log(this, "Allocated thread for local connection: "+
- t+":"+conn, Core.logger.DEBUG);
+ if(logDEBUG)
+ Core.logger.log(this, "Allocated thread for local connection: "+
+ t+":"+conn, Core.logger.DEBUG);
} else {
- Core.logger.log(this, "Running local connection in-thread: "+
- conn, Logger.DEBUG);
+ if(logDEBUG)
+ Core.logger.log(this, "Running local connection in-thread: "+
+ conn, Logger.DEBUG);
try {
runner.handle(conn);
} catch (RuntimeException t) {
@@ -204,6 +219,8 @@
LinkedList oldConnections = new LinkedList();
volatile boolean acceptingConnections = true;
+ int runningConnections = 0; // number of connections running
+
protected class ConnectionShell implements Runnable {
protected final Connection conn;
@@ -211,7 +228,7 @@
protected ConnectionShell(Connection conn) {
this.conn = conn;
- synchronized(this) {
+ synchronized(LocalNIOInterface.this) {
uppedRC = true;
runningConnections++;
}
@@ -222,17 +239,27 @@
this, Logger.MINOR);
acceptingConnections = false;
}
- if(Core.logger.shouldLog(Core.logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this, "RunningConnections now "+
runningConnections+", listening = "+
isListening(), Core.logger.DEBUG);
}
protected void finalize() {
- synchronized(this) {
+ synchronized(LocalNIOInterface.this) {
if(uppedRC == true) {
runningConnections--;
uppedRC = false;
+ if(runningConnections < lowRunningConnections
+ && !acceptingConnections) {
+ Core.logger.log(this, "Restarting processing connections "+
+ this, Logger.MINOR);
+ acceptingConnections = true;
+ }
+ if(logDEBUG)
+ Core.logger.log(this, "RunningConnections now "+
+ runningConnections+", listening = "+
+ isListening(), Core.logger.DEBUG);
}
}
}
@@ -255,7 +282,7 @@
e.printStackTrace(Core.logStream);
conn.close();
} finally {
- synchronized(this) {
+ synchronized(LocalNIOInterface.this) {
runningConnections--;
uppedRC = false;
}
@@ -265,7 +292,7 @@
this, Logger.MINOR);
acceptingConnections = true;
}
- if(Core.logger.shouldLog(Core.logger.DEBUG))
+ if(logDEBUG)
Core.logger.log(this, "RunningConnections now "+
runningConnections+", listening = "+
isListening(), Core.logger.DEBUG);
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs