Good evening,

I am using Ruby on Rails and BaseX for some hobby projects, and I have noticed the new Ruby client API + BaseX 7.0 causes java.net.SocketExceptions (see bottom of this message for complete error + stack trace) on the server. After inspecting the new client code, this seemed to have been caused by the new query iteration method which uses a cache. Reproducing this is easy; execute the QueryExample.rb script from the repository (make sure to first remove 'query.init', which is still in the example but has been removed from the API). It raises the Exception every single time for me.

Note the query does seem to return the expected result so I could just ignore the Exception but that does not seem like the right thing to do :)

On a side note, the 'if more()' in the 'next' method seems superfluous as query.next should only be called inside a 'while query.more' loop anyway. Effectively 'query.more' is now called twice in that loop before the cache is read.

Kind regards,
Daniël Knippers

ps. I'm using Java 1.6.0_27, and the error occurs on the stable BaseX 7.0 as well as on snapshot 170343 (7.0.1 RC1). The error below is from the 7.0.1 RC1 version. Server and client were ran from the same machine.

================= <error> =================
java.net.SocketException: Connection reset by peer: socket write error
java.net.SocketOutputStream.socketWrite0(Native Method)
java.net.SocketOutputStream.socketWrite(Unknown Source)
java.net.SocketOutputStream.write(Unknown Source)
org.basex.io.out.BufferOutput.flush(BufferOutput.java:52)
org.basex.io.out.PrintOutput.flush(PrintOutput.java:149)
org.basex.server.ClientListener.send(ClientListener.java:504)
org.basex.server.ClientListener.info(ClientListener.java:326)
org.basex.server.ClientListener.run(ClientListener.java:212)
================= </error> =================

=============== <caused_by> ===============
def more()
  if @cache.length == 0
    @session.write(4.chr)
    @session.send(@id)
    while(@session.read == 1.chr)
      @cache << @session.receive
    end
  end
  return @pos < @cache.length
end

def next
  if more()
    @pos += 1
    return @cache[@pos - 1]
  end
end
=============== </caused_by> ===============