Improved upstream connectivity handling

Upstream server disconnects are now gracefully handled.
Some basic structures added that should support connection pooling in
future commits.