Skip to content

Commit 7a74aeb

Browse files
committed
Add a default value to the timeout in InstanceManager::StopInstanceGroup
Every caller was passing the same values.
1 parent 8d71b7c commit 7a74aeb

5 files changed

Lines changed: 11 additions & 23 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "cuttlefish/host/commands/cvd/cli/commands/remove.h"
1818

19-
#include <chrono>
2019
#include <string>
2120
#include <vector>
2221

@@ -94,7 +93,7 @@ Result<void> RemoveCvdCommandHandler::StopGroup(
9493
return {};
9594
}
9695
CF_EXPECT(instance_manager_.StopInstanceGroup(
97-
group, std::chrono::seconds(5), InstanceDirActionOnStop::Clear));
96+
group, InstanceDirActionOnStop::Clear));
9897
return {};
9998
}
10099

base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <unistd.h>
2525

2626
#include <algorithm>
27-
#include <chrono>
2827
#include <cstdio>
2928
#include <cstdlib>
3029
#include <cstring>
@@ -504,7 +503,7 @@ Result<void> CvdStartCommandHandler::Handle(const CommandRequest& request) {
504503

505504
LOG(INFO) << "Stopping device...";
506505
CF_EXPECT(instance_manager_.StopInstanceGroup(
507-
group, std::chrono::seconds(5), InstanceDirActionOnStop::Keep, {}));
506+
group, InstanceDirActionOnStop::Keep));
508507
LOG(INFO) << "Device stopped.";
509508
return monitor_res;
510509
}

base/cvd/cuttlefish/host/commands/cvd/cli/commands/stop.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ namespace {
4141

4242
constexpr char kSummaryHelpText[] = "Stop Cuttlefish instances";
4343

44-
struct StopFlags {
45-
size_t wait_for_launcher_secs = 5;
46-
bool clear_instance_dirs = false;
47-
};
4844
} // namespace
4945

5046
CvdStopCommandHandler::CvdStopCommandHandler(InstanceManager& instance_manager)
@@ -80,10 +76,10 @@ Result<void> CvdStopCommandHandler::Handle(const CommandRequest& request) {
8076
}
8177

8278
Result<void> stop_outcome = instance_manager_.StopInstanceGroup(
83-
group, launcher_timeout,
79+
group,
8480
flags_.clear_instance_dirs ? InstanceDirActionOnStop::Clear
8581
: InstanceDirActionOnStop::Keep,
86-
instance_nums);
82+
launcher_timeout.value_or(std::chrono::seconds(0)), instance_nums);
8783

8884
GatherVmStopMetrics(group);
8985

base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ Result<void> InstanceManager::UpdateInstanceGroup(
212212
}
213213

214214
Result<void> InstanceManager::StopInstanceGroup(
215-
LocalInstanceGroup& group,
216-
std::optional<std::chrono::seconds> launcher_timeout,
217-
InstanceDirActionOnStop instance_dir_action,
215+
LocalInstanceGroup& group, InstanceDirActionOnStop instance_dir_action,
216+
std::chrono::seconds launcher_timeout,
218217
const std::vector<unsigned>& instance_nums) {
219218
// Validate that the requested instances actually belong to this group
220219
std::set<unsigned> valid_ids;
@@ -231,14 +230,10 @@ Result<void> InstanceManager::StopInstanceGroup(
231230

232231
const auto stop_bin = CF_EXPECT(StopBin(group.HostArtifactsPath()));
233232
const auto stop_bin_path = group.HostArtifactsPath() + "/bin/" + stop_bin;
234-
int wait_for_launcher_secs = 0;
235-
if (launcher_timeout.has_value()) {
236-
wait_for_launcher_secs = launcher_timeout->count();
237-
}
238233
Result<void> cmd_result = RunStopCvd(StopCvdParams{
239234
.bin_path = stop_bin_path,
240235
.home_dir = group.HomeDir(),
241-
.wait_for_launcher_secs = wait_for_launcher_secs,
236+
.wait_for_launcher_secs = static_cast<int>(launcher_timeout.count()),
242237
.clear_runtime_dirs =
243238
instance_dir_action == InstanceDirActionOnStop::Clear,
244239
.instance_nums = instance_nums,
@@ -271,8 +266,8 @@ Result<void> InstanceManager::Clear() {
271266
for (auto& group : instance_groups) {
272267
// Only stop running instances.
273268
if (group.HasActiveInstances()) {
274-
auto stop_result = StopInstanceGroup(group, std::chrono::seconds(5),
275-
InstanceDirActionOnStop::Clear);
269+
Result<void> stop_result =
270+
StopInstanceGroup(group, InstanceDirActionOnStop::Clear);
276271
if (!stop_result.ok()) {
277272
LOG(ERROR) << stop_result.error();
278273
}

base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ class InstanceManager {
8383
// Stops the device by asking it over the control socket. If launcher_timeout
8484
// has a value, it will wait for at most that time before returning an error.
8585
Result<void> StopInstanceGroup(
86-
LocalInstanceGroup& group,
87-
std::optional<std::chrono::seconds> launcher_timeout,
88-
InstanceDirActionOnStop instance_dir_action,
86+
LocalInstanceGroup& group, InstanceDirActionOnStop instance_dir_action,
87+
std::chrono::seconds launcher_timeout = std::chrono::seconds(5),
8988
const std::vector<unsigned>& instance_nums = {});
9089

9190
private:

0 commit comments

Comments
 (0)