If an error occurs on creating the context for console or import, we would fail to unlock the state. Fix this by unlocking slightly earlier. Affects console and import commands. Fixes #23318