Skip to content

Commit 4fc12c8

Browse files
authored
Add nil guard to ProcessModel.run_action_user (#4879)
* prevents exceptions "docker? delegated to app, but app is nil" when listing large number of processes on a live system
1 parent 9d2908e commit 4fc12c8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/models/runtime/process_model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def started_command
385385
def run_action_user
386386
return user if user.present?
387387

388-
docker? ? docker_run_action_user : AppModel::DEFAULT_CONTAINER_USER
388+
app&.docker? ? docker_run_action_user : AppModel::DEFAULT_CONTAINER_USER
389389
end
390390

391391
def specified_or_detected_command

spec/unit/models/runtime/process_model_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,17 @@ def act_as_cf_admin
747747
end
748748
end
749749
end
750+
751+
context 'when the associated app is nil' do
752+
before do
753+
process.app = nil
754+
end
755+
756+
it 'does not raise an error and returns nil' do
757+
expect { process.run_action_user }.not_to raise_error
758+
expect(process.run_action_user).to eq('vcap')
759+
end
760+
end
750761
end
751762

752763
describe '#specified_or_detected_command' do

0 commit comments

Comments
 (0)