Hopefully fixed a threading issue. Connections would work fine when accessed by a single query thread, but would fail for strange reasons when multiple HTTP requests were processed simulatenously. This should now be fixed, although we need to check whether this is the optimal solution.