substack/bouncy — pull request #12 by shripadk (2011-11-30 13:18:50+00:00)
Title: Open ports not being closed. Websocket disconnect event not emitted.

While performing a load test the 64k ephemeral port limit was reached very early. Couldn't open any more connections without bringing down the proxy.

A simple test:

`netstat -n | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }'`

shows that ports in the ESTABLISHED state lingered even after the client disconnected. The fix was simple enough: close the stream when the socket is closed.

All tests pass.