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