Potential deadlock on startup

This is the same issue as brought up by @rtecco in https://gist.github.com/rtecco/9945119

Here's a full dump of of blocked state in real life: https://gist.github.com/kjk/33ec3bdf079e43869d14

The issue is that: ConnectionMaxInFlight() takes RLock() and then calls MaxInFlight() which also takes RLock(). That is not a problem unless some other place takes (or even attempts to) Lock(), in which case the second RLock() will block and deadlock happens. In the dump below the place that is waiting in Lock() is ConnectToLookupd().

This RLock() behavior is un-intuitive enough that I had to write a test program to test that this is how it works: https://gist.github.com/shurcooL/e0639ec703e3282200e9

Note: there might be other places where RLock() is called recursively and therefore susceptible to this problem. An easy fix is to change them all to Lock(), that will immediately deadlock in such cases.

A full program that shows the problem (non-deterministically): https://gist.github.com/kjk/41cd49704c635b35bfd1

You just need to set correct nsqlookupdHosts, topic and channel variables.