fix container restart race condition

Finish container cleanup before setting the state to stopped.
Otherwise, for an application that exits quickly, a call to Restart
can allow Start to be called again before cleanup is done, resulting in
overritten data in the Container struct.
simplify the runtime Register reconnect logic

Refactor the Register code a little bit to make it easier to comprehend.
Merge pull request #2748 from jpoimboe/fix-restart-race-condition

fix container restart race condition
Merge pull request #2750 from jpoimboe/simplify-register-reconnect

Simplify the runtime Register reconnect logic