Handle timeouts better

- Handle timeout exceptions as well as connectionerror
- Add logging of above happening
- Make the timeout a configuration option
- Close connections on exception
- flake8 fixes