Message1662

Author amak
Recipients
Date 2007-06-28.19:44:24
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
OK, I'm reasonably confident that this is a java bug, related to the simultaneous use of input and output streams on a socket created by java.nio. See these bug reports for further info

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4509080
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774871

The problem is that the read and write methods of the InputStream and OutputStream returned by the java.nio.channels.Channels class are protected by a lock, which means that asocket cannot be read and written to at the same time by different threads. Which is exactly what your code is trying to do: ironic that your workaround for select breaks when select becomes available!

I think I can code around this bug, by creating PyFiles that read and write from Channels instead of [In|Out]putStreams, but I need to do more research to verify that.

In the meantime, you have a few possible solutions:

1. Use select! That's what its for; now that we've got it, why not use it :-)
2. Don't try to write and read simultaneously on the same PyFile returned from socket.makefile(). For example, insert a delay (you can see this by making your IncomingMessageHandler.run() method sleep for a second or two before it reads from the socket).
3. Directly use socket send and recv methods to talk to the socket; they are not affected by this locking problem.

Thanks for taking the time report this one. Your code made it very easy to find the problem, which could otherwise have been very difficult to track down.
History
Date User Action Args
2008-02-20 17:17:51adminlinkissue1744567 messages
2008-02-20 17:17:51admincreate