Reduce overhead for storing the key twice, and more overhead while looking up the connection to remove it after a failure.
std::map::emplace() is only available from gcc 4.8 on.
More robust and cancellable.