Adding an automatically handler for close before connect case

- Fixes #22