Fix bug reported in PR 791 : a race condition in ConnectionManager and Connection


CC @pwendell
rewrite of PR #791

I have not tested this unfortunately, due to time constraints - please take a look and review.