db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r446538 - in /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: DRDAConnThread.java NetworkServerControlImpl.java
Date Fri, 15 Sep 2006 07:52:19 GMT
Author: kahatlen
Date: Fri Sep 15 00:52:18 2006
New Revision: 446538

URL: http://svn.apache.org/viewvc?view=rev&rev=446538
Log:
DERBY-1326 (partial) Network server may abandon sessions when Derby
system is shutdown and this causes intermittent hangs in the client

Two small cleanups:

  Make NetworkServerControlImpl.startNetworkServer() remove the
  sessions it closes from sessionTable. Also, synchronize on runQueue
  to prevent modifications while the queue is traversed.

  Invoke closeSession() and close() in a finally clause in
  DRDAConnThread.handleException() to ensure proper closing of the
  session when an unexpected error happens.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?view=diff&rev=446538&r1=446537&r2=446538
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Fri Sep 15
00:52:18 2006
@@ -7491,46 +7491,46 @@
 	 */
 	private void handleException(Exception e)
 	{
-		String dbname = null;
-		if (database != null)
-			dbname = database.dbName;
-		
-		// protocol error - write error message and close session
-		if (e instanceof DRDAProtocolException)
-		{
-			try
-			{
-				DRDAProtocolException de = (DRDAProtocolException) e;
-				println2Log(dbname,session.drdaID, 
-							e.getMessage());
+		try {
+			if (e instanceof DRDAProtocolException) {
+				// protocol error - write error message
+				sendProtocolException((DRDAProtocolException) e);
+			} else {
+				// something unexpected happened
+				sendUnexpectedException(e);
 				server.consoleExceptionPrintTrace(e);
-				reader.clearBuffer();
-				de.write(writer);
-				finalizeChain();
-				closeSession();
-				close();
-			}
-			catch (DRDAProtocolException ioe)
-			{
-				// There may be an IO exception in the write.
-				println2Log(dbname,session.drdaID, 
-							e.getMessage());
-				server.consoleExceptionPrintTrace(ioe);
-				closeSession();
-				close();
 			}
-		}
-		else
-		{
-			// something unexpected happened so let's kill this thread
-			sendUnexpectedException(e);
-
-			server.consoleExceptionPrintTrace(e);
+		} finally {
+			// always close the session and stop the thread after handling
+			// these exceptions
 			closeSession();
 			close();
 		}
 	}
 	
+	/**
+	 * Notice the client about a protocol error.
+	 *
+	 * @param de <code>DRDAProtocolException</code> to be sent
+	 */
+	private void sendProtocolException(DRDAProtocolException de) {
+		String dbname = null;
+		if (database != null) {
+			dbname = database.dbName;
+		}
+
+		try {
+			println2Log(dbname, session.drdaID, de.getMessage());
+			server.consoleExceptionPrintTrace(de);
+			reader.clearBuffer();
+			de.write(writer);
+			finalizeChain();
+		} catch (DRDAProtocolException ioe) {
+			// There may be an IO exception in the write.
+			println2Log(dbname, session.drdaID, de.getMessage());
+			server.consoleExceptionPrintTrace(ioe);
+		}
+	}
 
 	/**
 	 * Send unpexpected error to the client

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?view=diff&rev=446538&r1=446537&r2=446538
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Fri Sep 15 00:52:18 2006
@@ -743,9 +743,14 @@
 					// exception), so we need to clean up first.
 
 						// Close and remove sessions on runQueue.
-						for (int i = 0; i < runQueue.size(); i++)
-							((Session)runQueue.get(i)).close();
-						runQueue.clear();
+						synchronized (runQueue) {
+							for (int i = 0; i < runQueue.size(); i++) {
+								Session s = (Session) runQueue.get(i);
+								s.close();
+								removeFromSessionTable(s.getConnNum());
+							}
+							runQueue.clear();
+						}
 
 						// Close and remove DRDAConnThreads on threadList.
 						for (int i = 0; i < threadList.size(); i++)



Mime
View raw message