Fix run_query connection timeout issues.

Solves run_query timeout issues by creating a new connection if the last one times out.
Ok but I would DRY this by pulling these two lines into a function that took `conn`, so you're not repeating yourself below