Based on the second code snippet in the link Patrick found, I've written an alternate patch (ZOOKEEPER-1197_shutdown.patch) that waits for the client to shutdown the input connection before closing the socket.
I've managed to reproduce the problem locally for testing:
0. My base setup: trunk zk checkout, Ubuntu 12.04, Oracle Java 6, no fancy zoo.cfg
1. I wrote a new 4lw, "long", that prints 100k '.'s followed by a '!' (so you can see if it's truncated). See long_4lw.patch.
2. Slow down your localhost connection: sudo tc qdisc add dev lo root netem delay 1000ms
(To undo this command: sudo tc qdisc del dev lo root)
3. Start a zk server with ./bin/zkServer.sh start
4. Send a long command: echo long | nc localhost 2181 (I've also been using FourLetterWordMain)
This should fill your terminal with dots, but shouldn't end with a !. If you see the !, the output wasn't truncated (i.e., you haven't hit the bug).
The new patch fixes the bug with this setup. Camille's patch also fixes it, although I do not fully understand how Since Camille reports having problems even after applying her patch (which I could not reproduce), this patch probably needs further testing as well. It would also be useful to test with a variety of clients (it sounds like this is the standard way to close a TCP connection, but I'm not positive every client will shut down the connection correctly).