Fixed resource leaks due to errors

@alertlogic/lm3-backend @alavrik-al @alebedevich 
Please review. I've verified (in test environment) that my changes fixed the issue, but my Erlang version is different from production so I can't really hot-load the code without building it elsewhere, so I'd rather just do a fresh build of psychic and deploy it as a package (especially that some of my changes require the app to be restarted anyway).

Fixed connection leaks on errors
Ensured the worker process gets exited on timeouts
Added configurable socket options