If self.con is not set, don't call end on it.

Currently, if you call `close` on the `Connection` object we don't check if `con` is set before calling `con.end()`. This means code will throw if `con` is not set.

This branch adds a check and only calls `con.end()` if `con` is set.