Pushed to upstream

cc/ @sergiogonzalez @adolfopa @cgoncas @migue.  Reverted as portal cannot start properly with original changes, and the fix caused more regressions