The static connection counter caused a race condition.

Moving the connection id counter into conncache solves it, as well as simplifying
the related logic.

This can be verified by testing under ThreadSanitizer in a multithreaded environment.