On Sat, Apr 4, 2009 at 2:56 AM, Andrea Gariboldi <firstname.lastname@example.org>
here is where the buffer is finally wrote:
org.apache.mina.core.polling.AbstractPollingIoProcessor [line: 758] : localWrittenBytes = write(session, buf, length);
Yeah but this should be called when each SearchResultEntry is written back to the client. It's really worrisome that a session.write() is not resulting in a processor write back to the client on it's socket.
It looks like this is not called until a SearchResponseDoneImpl
is writed and encoded here:
Yep this is the problem.
org.apache.directory.server.ldap.handlers-SearchHandler [line: 951] : session.getIoSession().write( done );
We properly perform a session.write() here:
org.apache.directory.server.ldap.handlers-SearchHandler [line: 326] :
session.getIoSession().write( generateResponse( session, req, entry ) );
If this is not trigger a processor write() on the client socket, then we might want to consider using a WriteFuture to force a write before continuing. However I think this may hide the true problem in MINA. Regardless give that a try and see if it prevents entry responses from collecting in the queue. Here's what the patch might look like below. NOTE this is not the best way to handle this but just something used to test. I would use a timeout.
Time out based wait on WriteFuture might be a crude yet easy way to throttle responses to slow clients.
--- protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (revision 761433)
+++ protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (working copy)
@@ -59,6 +59,7 @@
@@ -323,7 +324,9 @@
ClonedServerEntry entry = cursor.get();
- session.getIoSession().write( generateResponse( session, req, entry ) );
+ WriteFuture future = session.getIoSession().write(
+ generateResponse( session, req, entry ) );