<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1253,6 +1253,8 @@ public final class MemcachedClient extends SpyThread {
 				logRunException(e);
 			} catch(ClosedSelectorException e) {
 				logRunException(e);
+			} catch(IllegalStateException e) {
+				logRunException(e);
 			}
 		}
 		getLogger().info(&quot;Shut down memcached client&quot;);</diff>
      <filename>src/main/java/net/spy/memcached/MemcachedClient.java</filename>
    </modified>
    <modified>
      <diff>@@ -258,12 +258,12 @@ public final class MemcachedConnection extends SpyObject {
 					assert !channel.isConnected() : &quot;connected&quot;;
 				}
 			} else {
-				if(sk.isWritable()) {
-					handleWrites(sk, qa);
-				}
 				if(sk.isReadable()) {
 					handleReads(sk, qa);
 				}
+				if(sk.isWritable()) {
+					handleWrites(sk, qa);
+				}
 			}
 		} catch(Exception e) {
 			// Various errors occur on Linux that wind up here.  However, any</diff>
      <filename>src/main/java/net/spy/memcached/MemcachedConnection.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6a38bf7b3b190035e35133e8b08056ceb86d2eaf</id>
    </parent>
  </parents>
  <author>
    <name>Dustin Sallings</name>
    <email>dustin@spy.net</email>
  </author>
  <url>http://github.com/dustin/java-memcached-client/commit/0be1844a79e2d9ecd635e770faf479f3a221be87</url>
  <id>0be1844a79e2d9ecd635e770faf479f3a221be87</id>
  <committed-date>2008-05-13T22:20:37-07:00</committed-date>
  <authored-date>2008-05-13T22:18:58-07:00</authored-date>
  <message>Read before writes and expect IllegalStateException.

These are two measures that are helping with the queue overflow
problems.

Firstly, the IllegalStateException is thrown whenever you attempted to
add to a queue that's full.  If that happens internally, I don't want
the IO thread to crash, so I add it to the normal ``expected
exceptions'' list.

Secondly, reading before writing helps keep the read buffer ready for
new data.  When writing first, the write will have to transition to a
read and may cause the read buffer to overflow.  It still may happen,
but by servicing the reads first I can at least get the complete ones
popped out before piling new ones in (since writes are almost always
smaller and likely to transition).</message>
  <tree>f17bbf319e48839119dfef8e39f58803338dbb87</tree>
  <committer>
    <name>Dustin Sallings</name>
    <email>dustin@spy.net</email>
  </committer>
</commit>
