`undefined method `[]' for nil:NilClass` error during upgrading

Summary

undefined method []' for nil:NilClass` error during upgrading.

Steps to reproduce

In a VPS (OpenVZ-based):

sudo apt update
sudo apt dist-upgrade -y

Also, sudo gitlab-ctl reconfigure generates same error messages now.

What is the current bug behavior?

During upgrading, it shows the following errors:

Relevant File Content:
----------------------
/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/attributes/default.rb:

644:  default['gitlab']['gitlab-workhorse']['log_format'] = "json"
645:  default['gitlab']['gitlab-workhorse']['env_directory'] = '/opt/gitlab/etc/gitlab-workhorse/env'
646:  default['gitlab']['gitlab-workhorse']['env'] = {
647:    'PATH' => "#{node['package']['install-dir']}/bin:#{node['package']['install-dir']}/embedded/bin:/bin:/usr/bin",
648:    'HOME' => node['gitlab']['user']['home'],
649:    'SSL_CERT_DIR' => "#{node['package']['install-dir']}/embedded/ssl/certs/"
650:  }
651>> default['gitlab']['gitlab-workhorse']['image_scaler_max_procs'] = [2, node['cpu']['total'].to_i / 2].max
652:  default['gitlab']['gitlab-workhorse']['image_scaler_max_filesize'] = 250_000
653:  default['gitlab']['gitlab-workhorse']['consul_service_name'] = 'workhorse'
654:  default['gitlab']['gitlab-workhorse']['consul_service_meta'] = nil
655:  
656:  ####
657:  # mailroom
658:  ####
659:  default['gitlab']['mailroom']['enable'] = false
660:  default['gitlab']['mailroom']['ha'] = false

Have tried the workaround in #4398 (closed) by adding node['cpu']['total'] = '4' after line 650, but it doesn't work since default.rb is always replaced.

What is the expected correct behavior?

Have upgraded successfully.

Relevant logs

Relevant logs
N/A

Details of package version

Provide the package version installation details
```
$ dpkg-query -l "gitlab-*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                 Version         Architecture    Description
+++-====================-===============-===============-==============================================
iF  gitlab-ce            15.1.0-ce.0     amd64           GitLab Community Edition (including NGINX, Pos
un  gitlab-ci-multi-runn                     (no description available)
un  gitlab-ci-multi-runn                     (no description available)
un  gitlab-ee                                (no description available)
un  gitlab-fips                              (no description available)
ii  gitlab-runner        15.1.0          amd64           GitLab Runner
un  gitlab-runner-beta                       (no description available)
un  gitlab-runner-fips                       (no description available)
```

Environment details

  • Operating System: Ubuntu 18.04 LTS (bionic)
  • Installation Target, remove incorrect values:
    • VM: ServerCheap VPS (OpenVZ)
  • Installation Type, remove incorrect values:
    • Upgrade from version 15.0.0-ce.0
  • Is there any other software running on the machine: no
  • Is this a single or multiple node installation?
  • Resources
    • CPU: 4 virtual CPUs
    • Memory total:
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           8.0G        1.2G        3.2G         24M        3.6G        6.8G
Swap:          1.3G        648K        1.3G

Configuration details

Provide the relevant sections of `/etc/gitlab/gitlab.rb`
N/A