Make connection valid check time out after 3 seconds.

The nonexistent timeout was causing thread deadlocks, resulting in running out of memory crashes.
Close file stream
Merge pull request #45 from NoBullcraft/master

Fix some leaky things