I'm experimenting using fastcgi on nginx, but I've run into some problems. Nginx doesn't reuse connections, it gives 0 in BeginRequest flags, so the application should close the connection after the request has finished.
I have the following code for closing:
socket.shutdown(SocketShutdown.BOTH);
socket.close();
The problem is that the connections are not actually closed.. They linger on as TIME_WAIT, and nginx (or something) wont't keep opening new connections. My guess is I'm doing something wrong when closing the sockets, but I don't know what.. On a related note - how can I get nginx to keep connections open?
This is using nginx 1.0.6 and D 2.055
EDIT: Haven't gotten any closer, but I also checked the linger option, and it's off:
linger l;
socket.getOption(SocketOptionLevel.SOCKET, SocketOption.LINGER, l);
assert(l.on == 0); // off
getOption
returns 4 though.. No idea what that means. The return value is undocumented.
EDIT: I've also tried using TCP_NODELAY on the last message sent, but this didn't have any effect either:
socket.setOption(SocketOptionLevel.SOCKET, SocketOption.TCP_NODELAY, 1);
EDIT: nginx 1.1.4 supportes keep alive connections. This doesn't work as expected though.. Is correctly report that the server is responsible for connection lifetime management, but it still creates a new socket for each request.