Use thread-local variables to prevent recursive #connect invocations, and instead bail out immediately in a recursive connect scenario. Resolves mutex deadlocks and prevents potential infinite recursion in weird networking circumstances.