|
5 | 5 | import java.io.IOException; |
6 | 6 | import java.net.ServerSocket; |
7 | 7 | import java.net.SocketException; |
| 8 | +import java.nio.*; |
8 | 9 | import java.util.ArrayList; |
9 | 10 | import java.util.Date; |
10 | 11 | import java.util.HashMap; |
@@ -231,11 +232,28 @@ public void interrupt() { |
231 | 232 | protected void fail(final byte status, final int identifier, final InputOutputSocket inputOutputSocket) throws IOException { |
232 | 233 | logger.debug("FAIL {} {}", status, identifier); |
233 | 234 | final DataOutputStream outputStream = inputOutputSocket.getOutputStream(); |
234 | | - outputStream.writeByte(8); |
235 | | - outputStream.writeByte(status); |
236 | | - outputStream.writeInt(identifier); |
| 235 | + |
| 236 | + // Here comes the fun ... we need to write the feedback packet as one single packet |
| 237 | + // or the client will notice the connection to be closed before it read the complete packet. |
| 238 | + // But - only on linux, however. (I was not able to see that problem on Windows 7 or OS X) |
| 239 | + // What also helped was inserting a little sleep between the flush and closing the connection. |
| 240 | + // |
| 241 | + // I believe this is irregular (writing to a tcp socket then closing it should result in ALL data |
| 242 | + // being visible at the client) but interestingly in Netty there is (was) a similar problem: |
| 243 | + // https://github.com/netty/netty/issues/1952 |
| 244 | + // |
| 245 | + // Funnily that appeared as somebody ported this library to use netty. |
| 246 | + // |
| 247 | + // |
| 248 | + // |
| 249 | + ByteBuffer bb = ByteBuffer.allocate(6); |
| 250 | + bb.put((byte) 8); |
| 251 | + bb.put(status); |
| 252 | + bb.putInt(identifier); |
| 253 | + outputStream.write(bb.array()); |
237 | 254 | outputStream.flush(); |
238 | 255 | inputOutputSocket.close(); |
| 256 | + logger.debug("FAIL - closed"); |
239 | 257 | } |
240 | 258 |
|
241 | 259 | private class FeedbackRunner extends Thread { |
|
0 commit comments