Skip to content

Instantly share code, notes, and snippets.

@csm
Created July 17, 2015 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csm/a574316637162c7336ee to your computer and use it in GitHub Desktop.
Save csm/a574316637162c7336ee to your computer and use it in GitHub Desktop.
import java.io.*;
import java.net.*;
public class NetTest {
public static void main(String[] argv) throws Throwable {
Socket socket = new Socket();
try {
System.out.println("connecting socket...");
socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 31337));
socket.connect(new InetSocketAddress(InetAddress.getByName(argv[0]), 4242));
System.out.printf("have socket; connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown());
OutputStream outStream = socket.getOutputStream();
OutputStreamWriter outWriter = new OutputStreamWriter(outStream);
System.out.printf("emitting test event...%n");
outWriter.write("put test.sample.event " + System.currentTimeMillis() + " 0.0 when=before\n");
outWriter.flush();
System.out.printf("sleeping for > 60s... connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown());
Thread.sleep(120 * 1000 + 500);
System.out.printf("slept, emitting test event... connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown());
outWriter.write("put test.sample.event " + System.currentTimeMillis() + " 0.0 when=after\n");
outWriter.flush();
} catch (Exception x) {
System.out.println("caught exception!");
x.printStackTrace(System.out);
} finally {
System.out.println("closing socket");
socket.close();
}
}
}
@csm
Copy link
Author

csm commented Jul 17, 2015

What dafuq is wrong with AWS ELBs?

If you connect the above to an ELB with a 60 second idle timeout, the socket will go to CLOSE_WAIT state, but the socket doesn't appear closed from the write side, and the write is still accepted. Oh, but the data written is dropped on the floor, and never makes it to the other side.

And. And! If you close the socket, the socket hangs around in LAST_ACK for a minute or so. Thanks Amazon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment