• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 2276402292

21 Jan 2026 11:56AM UTC coverage: 79.855%. First build
2276402292

push

gitlab-ci

michalkopczan
feat: Handle HTTP 429 Too Many Requests in deployment polling

Ticket: MEN-8850
Changelog: Title

Signed-off-by: Michal Kopczan <michal.kopczan@northern.tech>

30 of 35 new or added lines in 3 files covered. (85.71%)

7932 of 9933 relevant lines covered (79.86%)

13852.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/src/mender-update/daemon/states.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <mender-update/daemon/states.hpp>
16

17
#include <client_shared/conf.hpp>
18
#include <common/events_io.hpp>
19
#include <common/log.hpp>
20
#include <common/path.hpp>
21

22
#include <mender-update/daemon/context.hpp>
23
#include <mender-update/inventory.hpp>
24

25
namespace mender {
26
namespace update {
27
namespace daemon {
28

29
namespace conf = mender::client_shared::conf;
30
namespace error = mender::common::error;
31
namespace events = mender::common::events;
32
namespace kv_db = mender::common::key_value_database;
33
namespace path = mender::common::path;
34
namespace log = mender::common::log;
35

36
namespace main_context = mender::update::context;
37
namespace inventory = mender::update::inventory;
38

39
class DefaultStateHandler {
40
public:
41
        void operator()(const error::Error &err) {
294✔
42
                if (err != error::NoError) {
294✔
43
                        log::Error(err.String());
23✔
44
                        poster.PostEvent(StateEvent::Failure);
23✔
45
                        return;
23✔
46
                }
47
                poster.PostEvent(StateEvent::Success);
271✔
48
        }
49

50
        sm::EventPoster<StateEvent> &poster;
51
};
52

53
static void DefaultAsyncErrorHandler(sm::EventPoster<StateEvent> &poster, const error::Error &err) {
412✔
54
        if (err != error::NoError) {
412✔
55
                log::Error(err.String());
×
56
                poster.PostEvent(StateEvent::Failure);
×
57
        }
58
}
412✔
59

60
void EmptyState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
152✔
61
        // Keep this state truly empty.
62
}
152✔
63

64
void InitState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
59✔
65
        // I will never run - just a placeholder to start the state-machine at
66
        poster.PostEvent(StateEvent::Started); // Start the state machine
59✔
67
}
59✔
68

69
void StateScriptState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
1,052✔
70
        string state_name {script_executor::Name(this->state_, this->action_)};
1,052✔
71
        log::Debug("Executing the  " + state_name + " State Scripts...");
2,104✔
72
        auto err = this->script_.AsyncRunScripts(
73
                this->state_,
74
                this->action_,
75
                [state_name, &poster](error::Error err) {
7,869✔
76
                        if (err != error::NoError) {
1,052✔
77
                                log::Error(
21✔
78
                                        "Received error: (" + err.String() + ") when running the State Script scripts "
42✔
79
                                        + state_name);
63✔
80
                                poster.PostEvent(StateEvent::Failure);
21✔
81
                                return;
21✔
82
                        }
83
                        log::Debug("Successfully ran the " + state_name + " State Scripts...");
2,062✔
84
                        poster.PostEvent(StateEvent::Success);
1,031✔
85
                },
86
                this->on_error_);
2,104✔
87

88
        if (err != error::NoError) {
1,052✔
89
                log::Error(
×
90
                        "Failed to schedule the state script execution for: " + state_name
×
91
                        + " got error: " + err.String());
×
92
                poster.PostEvent(StateEvent::Failure);
×
93
                return;
94
        }
95
}
96

97

98
void SaveStateScriptState::OnEnterSaveState(Context &ctx, sm::EventPoster<StateEvent> &poster) {
278✔
99
        return state_script_state_.OnEnter(ctx, poster);
278✔
100
}
101

102
void IdleState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
120✔
103
        log::Debug("Entering Idle state");
240✔
104
}
120✔
105

106
ScheduleNextPollState::ScheduleNextPollState(
×
107
        events::Timer &timer, const string &poll_action, const StateEvent event, int interval) :
108
        timer_ {timer},
109
        poll_action_ {poll_action},
110
        event_ {event},
111
        interval_ {interval} {
×
112
}
×
113

114
void ScheduleNextPollState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
119✔
115
        log::Debug("Scheduling the next " + poll_action_ + " in: " + to_string(interval_) + " seconds");
238✔
116
        timer_.AsyncWait(chrono::seconds(interval_), [this, &poster](error::Error err) {
119✔
117
                if (err != error::NoError) {
5✔
118
                        if (err.code != make_error_condition(errc::operation_canceled)) {
2✔
119
                                log::Error("Timer caused error: " + err.String());
×
120
                        }
121
                } else {
122
                        poster.PostEvent(event_);
3✔
123
                }
124
        });
5✔
125

126
        poster.PostEvent(StateEvent::Success);
119✔
127
}
119✔
128

129
SubmitInventoryState::SubmitInventoryState(int retry_interval_seconds, int retry_count) :
96✔
130
        backoff_ {chrono::seconds(retry_interval_seconds), retry_count} {
192✔
131
}
96✔
132

133
void SubmitInventoryState::HandlePollingError(Context &ctx, sm::EventPoster<StateEvent> &poster) {
×
134
        // When using short polling intervals, we should adjust the backoff to ensure
135
        // that the intervals do not exceed the maximum retry polling interval, which
136
        // converts the backoff to a fixed interval.
137
        chrono::milliseconds max_interval =
138
                chrono::seconds(ctx.mender_context.GetConfig().retry_poll_interval_seconds);
×
139
        if (max_interval < backoff_.SmallestInterval()) {
×
140
                backoff_.SetSmallestInterval(max_interval);
×
141
                backoff_.SetMaxInterval(max_interval);
×
142
        }
143
        auto exp_interval = backoff_.NextInterval();
×
144
        if (!exp_interval) {
×
145
                log::Debug(
×
146
                        "Not retrying with backoff, retrying InventoryPollIntervalSeconds: "
147
                        + exp_interval.error().String());
×
148
                return;
149
        }
150
        log::Info(
×
151
                "Retrying inventory polling in "
152
                + to_string(chrono::duration_cast<chrono::seconds>(*exp_interval).count()) + " seconds");
×
153

154
        ctx.inventory_timer.Cancel();
×
155
        ctx.inventory_timer.AsyncWait(*exp_interval, [&poster](error::Error err) {
×
156
                if (err != error::NoError) {
×
157
                        if (err.code != make_error_condition(errc::operation_canceled)) {
×
158
                                log::Error("Retry poll timer caused error: " + err.String());
×
159
                        }
160
                } else {
161
                        poster.PostEvent(StateEvent::InventoryPollingTriggered);
×
162
                }
163
        });
×
164
}
165

166
void SubmitInventoryState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
59✔
167
        log::Debug("Submitting inventory");
118✔
168

169
        auto handler = [this, &ctx, &poster](error::Error err) {
59✔
170
                if (err != error::NoError) {
59✔
171
                        log::Error("Failed to submit inventory: " + err.String());
×
172
                        // Replace the inventory poll timer with a backoff
173
                        HandlePollingError(ctx, poster);
×
174
                        poster.PostEvent(StateEvent::Failure);
×
175
                        return;
×
176
                }
177
                backoff_.Reset();
178
                ctx.inventory_client->has_submitted_inventory = true;
59✔
179
                poster.PostEvent(StateEvent::Success);
59✔
180
        };
59✔
181

182
        auto err = ctx.inventory_client->PushData(
183
                ctx.mender_context.GetConfig().paths.GetInventoryScriptsDir(),
59✔
184
                ctx.event_loop,
185
                ctx.http_client,
186
                handler);
59✔
187

188
        if (err != error::NoError) {
59✔
189
                // This is the only case the handler won't be called for us by
190
                // PushData() (see inventory::PushInventoryData()).
191
                handler(err);
×
192
        }
193
}
59✔
194

195
PollForDeploymentState::PollForDeploymentState(int retry_interval_seconds, int retry_count) :
99✔
196
        backoff_ {chrono::seconds(retry_interval_seconds), retry_count} {
198✔
197
}
99✔
198

199
void PollForDeploymentState::HandlePollingError(
14✔
200
        Context &ctx,
201
        sm::EventPoster<StateEvent> &poster,
202
        mender::update::deployments::CheckUpdatesAPIResponseError response) {
203
        // When using short polling intervals, we should adjust the backoff to ensure
204
        // that the intervals do not exceed the maximum retry polling interval, which
205
        // converts the backoff to a fixed interval.
206
        chrono::milliseconds max_interval =
207
                chrono::seconds(ctx.mender_context.GetConfig().retry_poll_interval_seconds);
14✔
208
        if (max_interval < backoff_.SmallestInterval()) {
14✔
209
                backoff_.SetSmallestInterval(max_interval);
×
210
                backoff_.SetMaxInterval(max_interval);
×
211
        }
212

213
        chrono::milliseconds interval;
214
        bool retry_after_defined {false};
215

216
        if (response.code.has_value() && response.code.value() == http::StatusTooManyRequests
14✔
217
                && response.headers.has_value()) {
24✔
218
                auto retry_after_header = response.headers.value().find("Retry-After");
20✔
219
                if (retry_after_header != response.headers.value().end()) {
10✔
220
                        auto exp_interval = http::HTTPDateToUnixTimestampFromNow(retry_after_header->second);
3✔
221
                        if (exp_interval.has_value()) {
3✔
222
                                interval = exp_interval.value();
3✔
223
                                retry_after_defined = true;
224
                        } else {
NEW
225
                                log::Debug("Could not get the Retry-After value from HTTP response");
×
226
                        }
227
                }
228
        }
229

230
        if (!retry_after_defined) {
3✔
231
                auto exp_interval = backoff_.NextInterval();
11✔
232
                if (!exp_interval) {
11✔
NEW
233
                        log::Debug(
×
234
                                "Not retrying with backoff, retrying with UpdatePollIntervalSeconds: "
NEW
235
                                + exp_interval.error().String());
×
236
                        return;
237
                }
238
                interval = exp_interval.value();
11✔
239
        }
240
        log::Info(
14✔
241
                "Retrying deployment polling in "
242
                + to_string(chrono::duration_cast<chrono::seconds>(interval).count()) + " seconds");
28✔
243

244
        ctx.deployment_timer.Cancel();
14✔
245
        ctx.deployment_timer.AsyncWait(interval, [&poster](error::Error err) {
14✔
246
                if (err != error::NoError) {
×
247
                        if (err.code != make_error_condition(errc::operation_canceled)) {
×
248
                                log::Error("Retry poll timer caused error: " + err.String());
×
249
                        }
250
                } else {
251
                        poster.PostEvent(StateEvent::DeploymentPollingTriggered);
×
252
                }
253
        });
14✔
254
}
255

256
void PollForDeploymentState::CheckNewDeploymentsHandler(
72✔
257
        Context &ctx,
258
        sm::EventPoster<StateEvent> &poster,
259
        mender::update::deployments::CheckUpdatesAPIResponse response) {
260
        if (!response) {
72✔
261
                log::Error("Error while polling for deployment: " + response.error().error.String());
28✔
262
                // Replace the update poll timer with a backoff
263
                HandlePollingError(ctx, poster, response.error());
14✔
264
                poster.PostEvent(StateEvent::Failure);
14✔
265
                return;
15✔
266
        } else if (!response.value()) {
58✔
267
                log::Info("No update available");
2✔
268
                poster.PostEvent(StateEvent::NothingToDo);
1✔
269
                if (not ctx.inventory_client->has_submitted_inventory) {
1✔
270
                        // If we have not submitted inventory successfully at least
271
                        // once, schedule this after receiving a successful response
272
                        // with no update. This enables inventory to be submitted
273
                        // immediately after the device has been accepted. If there
274
                        // is an update available, an inventory update will be
275
                        // scheduled at the end of it unconditionally.
276
                        poster.PostEvent(StateEvent::InventoryPollingTriggered);
×
277
                }
278

279
                backoff_.Reset();
280
                return;
1✔
281
        }
282
        backoff_.Reset();
283

284
        auto exp_data = ApiResponseJsonToStateData(response.value().value());
57✔
285
        if (!exp_data) {
57✔
286
                log::Error("Error in API response: " + exp_data.error().String());
×
287
                poster.PostEvent(StateEvent::Failure);
×
288
                return;
289
        }
290

291
        // Make a new set of update data.
292
        ctx.deployment.state_data.reset(new StateData(std::move(exp_data.value())));
57✔
293

294
        ctx.BeginDeploymentLogging();
57✔
295

296
        // This is a duplicate message to one logged when mender-update
297
        // starts, but this one goes into the deployment log.
298
        log::Info("Running mender-update " + conf::kMenderVersion);
114✔
299
        log::Info("Deployment with ID " + ctx.deployment.state_data->update_info.id + " started.");
114✔
300

301
        poster.PostEvent(StateEvent::DeploymentStarted);
57✔
302
        poster.PostEvent(StateEvent::Success);
57✔
303
}
304

305
void PollForDeploymentState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
59✔
306
        log::Debug("Polling for update");
118✔
307

308
        auto err = ctx.deployment_client->CheckNewDeployments(
309
                ctx.mender_context,
310
                ctx.http_client,
311
                [this, &ctx, &poster](mender::update::deployments::CheckUpdatesAPIResponse response) {
58✔
312
                        this->CheckNewDeploymentsHandler(ctx, poster, response);
58✔
313
                });
117✔
314

315
        if (err != error::NoError) {
59✔
316
                log::Error("Error when trying to poll for deployment: " + err.String());
2✔
317
                poster.PostEvent(StateEvent::Failure);
1✔
318
        }
319
}
59✔
320

321
void SaveState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
535✔
322
        assert(ctx.deployment.state_data);
323

324
        ctx.deployment.state_data->state = DatabaseStateString();
535✔
325

326
        log::Trace("Storing deployment state in the DB (database-string): " + DatabaseStateString());
1,070✔
327

328
        auto err = ctx.SaveDeploymentStateData(*ctx.deployment.state_data);
535✔
329
        if (err != error::NoError) {
535✔
330
                log::Error(err.String());
10✔
331
                if (err.code
10✔
332
                        == main_context::MakeError(main_context::StateDataStoreCountExceededError, "").code) {
10✔
333
                        poster.PostEvent(StateEvent::StateLoopDetected);
1✔
334
                        return;
335
                } else if (!IsFailureState()) {
9✔
336
                        // Non-failure states should be interrupted, but failure states should be
337
                        // allowed to do their work, even if a database error was detected.
338
                        poster.PostEvent(StateEvent::Failure);
2✔
339
                        return;
340
                }
341
        }
342

343
        OnEnterSaveState(ctx, poster);
532✔
344
}
345

346
void UpdateDownloadState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
54✔
347
        log::Debug("Entering Download state");
108✔
348

349
        auto req = make_shared<http::OutgoingRequest>();
54✔
350
        req->SetMethod(http::Method::GET);
54✔
351
        auto err = req->SetAddress(ctx.deployment.state_data->update_info.artifact.source.uri);
54✔
352
        if (err != error::NoError) {
54✔
353
                log::Error(err.String());
×
354
                poster.PostEvent(StateEvent::Failure);
×
355
                return;
356
        }
357

358
        err = ctx.download_client->AsyncCall(
54✔
359
                req,
360
                [&ctx, &poster](http::ExpectedIncomingResponsePtr exp_resp) {
107✔
361
                        if (!exp_resp) {
54✔
362
                                log::Error("Unexpected error during download: " + exp_resp.error().String());
×
363
                                poster.PostEvent(StateEvent::Failure);
×
364
                                return;
1✔
365
                        }
366

367
                        auto &resp = exp_resp.value();
54✔
368
                        if (resp->GetStatusCode() != http::StatusOK) {
54✔
369
                                log::Error(
1✔
370
                                        "Unexpected status code while fetching artifact: " + resp->GetStatusMessage());
2✔
371
                                poster.PostEvent(StateEvent::Failure);
1✔
372
                                return;
1✔
373
                        }
374

375
                        auto http_reader = resp->MakeBodyAsyncReader();
53✔
376
                        if (!http_reader) {
53✔
377
                                log::Error(http_reader.error().String());
×
378
                                poster.PostEvent(StateEvent::Failure);
×
379
                                return;
380
                        }
381
                        ctx.deployment.artifact_reader =
382
                                make_shared<events::io::ReaderFromAsyncReader>(ctx.event_loop, http_reader.value());
53✔
383
                        ParseArtifact(ctx, poster);
53✔
384
                },
385
                [](http::ExpectedIncomingResponsePtr exp_resp) {
54✔
386
                        if (!exp_resp) {
54✔
387
                                log::Error(exp_resp.error().String());
6✔
388
                                // Cannot handle error here, because this handler is called at the
389
                                // end of the download, when we have already left this state. So
390
                                // rely on this error being propagated through the BodyAsyncReader
391
                                // above instead.
392
                                return;
6✔
393
                        }
394
                });
108✔
395

396
        if (err != error::NoError) {
54✔
397
                log::Error(err.String());
×
398
                poster.PostEvent(StateEvent::Failure);
×
399
                return;
400
        }
401
}
402

403
void UpdateDownloadState::ParseArtifact(Context &ctx, sm::EventPoster<StateEvent> &poster) {
53✔
404
        string art_scripts_path = ctx.mender_context.GetConfig().paths.GetArtScriptsPath();
53✔
405

406
        // Clear the artifact scripts directory so we don't risk old scripts lingering.
407
        auto err = path::DeleteRecursively(art_scripts_path);
53✔
408
        if (err != error::NoError) {
53✔
409
                log::Error("When preparing to parse artifact: " + err.String());
×
410
                poster.PostEvent(StateEvent::Failure);
×
411
                return;
412
        }
413

414
        artifact::config::ParserConfig config {
53✔
415
                .artifact_scripts_filesystem_path = art_scripts_path,
416
                .artifact_scripts_version = 3,
417
                .artifact_verify_keys = ctx.mender_context.GetConfig().artifact_verify_keys,
53✔
418
        };
102✔
419
        auto exp_parser = artifact::Parse(*ctx.deployment.artifact_reader, config);
106✔
420
        if (!exp_parser) {
53✔
421
                log::Error(exp_parser.error().String());
×
422
                poster.PostEvent(StateEvent::Failure);
×
423
                return;
424
        }
425
        ctx.deployment.artifact_parser.reset(new artifact::Artifact(std::move(exp_parser.value())));
53✔
426

427
        auto exp_header = artifact::View(*ctx.deployment.artifact_parser, 0);
53✔
428
        if (!exp_header) {
53✔
429
                log::Error(exp_header.error().String());
×
430
                poster.PostEvent(StateEvent::Failure);
×
431
                return;
432
        }
433
        auto &header = exp_header.value();
53✔
434

435
        auto exp_matches = ctx.mender_context.MatchesArtifactDepends(header.header);
53✔
436
        if (!exp_matches) {
53✔
437
                log::Error(exp_matches.error().String());
2✔
438
                poster.PostEvent(StateEvent::Failure);
2✔
439
                return;
440
        } else if (!exp_matches.value()) {
51✔
441
                // reasons already logged
442
                poster.PostEvent(StateEvent::Failure);
1✔
443
                return;
444
        }
445

446
        log::Info("Installing artifact...");
100✔
447

448
        ctx.deployment.state_data->FillUpdateDataFromArtifact(header);
50✔
449

450
        ctx.deployment.state_data->state = Context::kUpdateStateDownload;
50✔
451

452
        assert(ctx.deployment.state_data->update_info.artifact.payload_types.size() == 1);
453

454
        // Initial state data save, now that we have enough information from the artifact.
455
        err = ctx.SaveDeploymentStateData(*ctx.deployment.state_data);
50✔
456
        if (err != error::NoError) {
50✔
457
                log::Error(err.String());
×
458
                if (err.code
×
459
                        == main_context::MakeError(main_context::StateDataStoreCountExceededError, "").code) {
×
460
                        poster.PostEvent(StateEvent::StateLoopDetected);
×
461
                        return;
462
                } else {
463
                        poster.PostEvent(StateEvent::Failure);
×
464
                        return;
465
                }
466
        }
467

468
        if (header.header.payload_type == "") {
50✔
469
                // Empty-payload-artifact, aka "bootstrap artifact".
470
                poster.PostEvent(StateEvent::NothingToDo);
1✔
471
                return;
472
        }
473

474
        auto exp_update_module =
475
                update_module::UpdateModule::Create(ctx.mender_context, header.header.payload_type);
49✔
476
        if (!exp_update_module.has_value()) {
49✔
477
                log::Error(
×
478
                        "Error creating an Update Module when parsing artifact: "
479
                        + exp_update_module.error().String());
×
480
                poster.PostEvent(StateEvent::Failure);
×
481
                return;
482
        }
483
        ctx.deployment.update_module = std::move(exp_update_module.value());
49✔
484

485
        err = ctx.deployment.update_module->CleanAndPrepareFileTree(
49✔
486
                ctx.deployment.update_module->GetUpdateModuleWorkDir(), header);
49✔
487
        if (err != error::NoError) {
49✔
488
                log::Error(err.String());
×
489
                poster.PostEvent(StateEvent::Failure);
×
490
                return;
491
        }
492

493
        err = ctx.deployment.update_module->AsyncProvidePayloadFileSizes(
49✔
494
                ctx.event_loop, [&ctx, &poster](expected::ExpectedBool download_with_sizes) {
49✔
495
                        if (!download_with_sizes.has_value()) {
49✔
496
                                log::Error(download_with_sizes.error().String());
×
497
                                poster.PostEvent(StateEvent::Failure);
×
498
                                return;
×
499
                        }
500
                        ctx.deployment.download_with_sizes = download_with_sizes.value();
49✔
501
                        DoDownload(ctx, poster);
49✔
502
                });
49✔
503

504
        if (err != error::NoError) {
49✔
505
                log::Error(err.String());
×
506
                poster.PostEvent(StateEvent::Failure);
×
507
                return;
508
        }
509
}
510

511
void UpdateDownloadState::DoDownload(Context &ctx, sm::EventPoster<StateEvent> &poster) {
49✔
512
        auto exp_payload = ctx.deployment.artifact_parser->Next();
49✔
513
        if (!exp_payload) {
49✔
514
                log::Error(exp_payload.error().String());
×
515
                poster.PostEvent(StateEvent::Failure);
×
516
                return;
517
        }
518
        ctx.deployment.artifact_payload.reset(new artifact::Payload(std::move(exp_payload.value())));
49✔
519

520
        auto handler = [&poster, &ctx](error::Error err) {
47✔
521
                if (err != error::NoError) {
49✔
522
                        log::Error(err.String());
2✔
523
                        poster.PostEvent(StateEvent::Failure);
2✔
524
                        return;
2✔
525
                }
526

527
                auto exp_payload = ctx.deployment.artifact_parser->Next();
47✔
528
                if (exp_payload) {
47✔
529
                        log::Error("Multiple payloads are not yet supported in daemon mode.");
×
530
                        poster.PostEvent(StateEvent::Failure);
×
531
                        return;
532
                } else if (
47✔
533
                        exp_payload.error().code
534
                        != artifact::parser_error::MakeError(artifact::parser_error::EOFError, "").code) {
47✔
535
                        log::Error(exp_payload.error().String());
×
536
                        poster.PostEvent(StateEvent::Failure);
×
537
                        return;
538
                }
539

540
                poster.PostEvent(StateEvent::Success);
47✔
541
        };
542

543
        if (ctx.deployment.download_with_sizes) {
49✔
544
                ctx.deployment.update_module->AsyncDownloadWithFileSizes(
1✔
545
                        ctx.event_loop, *ctx.deployment.artifact_payload, handler);
1✔
546
        } else {
547
                ctx.deployment.update_module->AsyncDownload(
48✔
548
                        ctx.event_loop, *ctx.deployment.artifact_payload, handler);
48✔
549
        }
550
}
551

552
void UpdateDownloadCancelState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
6✔
553
        log::Debug("Entering DownloadCancel state");
12✔
554
        ctx.download_client->Cancel();
6✔
555
        poster.PostEvent(StateEvent::Success);
6✔
556
}
6✔
557

558
SendStatusUpdateState::SendStatusUpdateState(optional<deployments::DeploymentStatus> status) :
×
559
        status_(status),
560
        mode_(FailureMode::Ignore) {
×
561
}
×
562

563
SendStatusUpdateState::SendStatusUpdateState(
192✔
564
        optional<deployments::DeploymentStatus> status,
565
        events::EventLoop &event_loop,
566
        int retry_interval_seconds,
567
        int retry_count) :
568
        status_(status),
569
        mode_(FailureMode::RetryThenFail),
570
        retry_(Retry {
192✔
571
                http::ExponentialBackoff(chrono::seconds(retry_interval_seconds), retry_count),
572
                event_loop}) {
576✔
573
}
192✔
574

575
void SendStatusUpdateState::SetSmallestWaitInterval(chrono::milliseconds interval) {
182✔
576
        if (retry_) {
182✔
577
                retry_->backoff.SetSmallestInterval(interval);
182✔
578
        }
579
}
182✔
580

581
void SendStatusUpdateState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
246✔
582
        // Reset this every time we enter the state, which means a new round of retries.
583
        if (retry_) {
246✔
584
                retry_->backoff.Reset();
585
        }
586

587
        DoStatusUpdate(ctx, poster);
246✔
588
}
246✔
589

590
void SendStatusUpdateState::DoStatusUpdate(Context &ctx, sm::EventPoster<StateEvent> &poster) {
265✔
591
        assert(ctx.deployment_client);
592
        assert(ctx.deployment.state_data);
593

594
        log::Info("Sending status update to server");
530✔
595

596
        auto result_handler = [this, &ctx, &poster](const error::Error &err) {
552✔
597
                if (err != error::NoError) {
265✔
598
                        log::Error("Could not send deployment status: " + err.String());
50✔
599

600
                        if (err.code == deployments::MakeError(deployments::DeploymentAbortedError, "").code) {
25✔
601
                                // If the deployment was aborted upstream it is an immediate
602
                                // failure, even if retry is enabled.
603
                                poster.PostEvent(StateEvent::DeploymentAborted);
3✔
604
                                return;
3✔
605
                        }
606

607
                        switch (mode_) {
22✔
608
                        case FailureMode::Ignore:
609
                                break;
2✔
610
                        case FailureMode::RetryThenFail:
20✔
611

612
                                auto exp_interval = retry_->backoff.NextInterval();
20✔
613
                                if (!exp_interval) {
20✔
614
                                        log::Error(
1✔
615
                                                "Giving up on sending status updates to server: "
616
                                                + exp_interval.error().String());
2✔
617
                                        poster.PostEvent(StateEvent::Failure);
1✔
618
                                        return;
619
                                }
620

621
                                log::Info(
19✔
622
                                        "Retrying status update after "
623
                                        + to_string(chrono::duration_cast<chrono::seconds>(*exp_interval).count())
38✔
624
                                        + " seconds");
38✔
625
                                retry_->wait_timer.AsyncWait(
19✔
626
                                        *exp_interval, [this, &ctx, &poster](error::Error err) {
38✔
627
                                                // Error here is quite unexpected (from a timer), so treat
628
                                                // this as an immediate error, despite Retry flag.
629
                                                if (err != error::NoError) {
19✔
630
                                                        log::Error(
×
631
                                                                "Unexpected error in SendStatusUpdateState wait timer: "
632
                                                                + err.String());
×
633
                                                        poster.PostEvent(StateEvent::Failure);
×
634
                                                        return;
×
635
                                                }
636

637
                                                // Try again. Since both status and logs are sent
638
                                                // from here, there's a chance this might resubmit
639
                                                // the status, but there's no harm in it, and it
640
                                                // won't happen often.
641
                                                DoStatusUpdate(ctx, poster);
19✔
642
                                        });
19✔
643
                                return;
19✔
644
                        }
645
                }
646

647
                poster.PostEvent(StateEvent::Success);
242✔
648
        };
265✔
649

650
        deployments::DeploymentStatus status;
651
        if (status_) {
265✔
652
                status = status_.value();
172✔
653
        } else {
654
                // If nothing is specified, grab success/failure status from the deployment status.
655
                if (ctx.deployment.failed) {
93✔
656
                        status = deployments::DeploymentStatus::Failure;
657
                } else {
658
                        status = deployments::DeploymentStatus::Success;
659
                }
660
        }
661

662
        // Push status.
663
        log::Debug("Pushing deployment status: " + DeploymentStatusString(status));
530✔
664
        auto err = ctx.deployment_client->PushStatus(
665
                ctx.deployment.state_data->update_info.id,
265✔
666
                status,
667
                "",
668
                ctx.http_client,
669
                [result_handler, &ctx](error::Error err) {
75✔
670
                        // If there is an error, we don't submit logs now, but call the handler,
671
                        // which may schedule a retry later. If there is no error, and the
672
                        // deployment as a whole was successful, then also call the handler here,
673
                        // since we don't need to submit logs at all then.
674
                        if (err != error::NoError || !ctx.deployment.failed) {
265✔
675
                                result_handler(err);
190✔
676
                                return;
190✔
677
                        }
678

679
                        // Push logs.
680
                        err = ctx.deployment_client->PushLogs(
75✔
681
                                ctx.deployment.state_data->update_info.id,
75✔
682
                                ctx.deployment.logger->LogFilePath(),
150✔
683
                                ctx.http_client,
684
                                result_handler);
75✔
685

686
                        if (err != error::NoError) {
75✔
687
                                result_handler(err);
×
688
                        }
689
                });
530✔
690

691
        if (err != error::NoError) {
265✔
692
                result_handler(err);
×
693
        }
694

695
        // No action, wait for reply from status endpoint.
696
}
265✔
697

698
void UpdateInstallState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
42✔
699
        log::Debug("Entering ArtifactInstall state");
84✔
700

701
        DefaultAsyncErrorHandler(
42✔
702
                poster,
703
                ctx.deployment.update_module->AsyncArtifactInstall(
42✔
704
                        ctx.event_loop, DefaultStateHandler {poster}));
42✔
705
}
42✔
706

707
void UpdateCheckRebootState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
73✔
708
        DefaultAsyncErrorHandler(
73✔
709
                poster,
710
                ctx.deployment.update_module->AsyncNeedsReboot(
73✔
711
                        ctx.event_loop, [&ctx, &poster](update_module::ExpectedRebootAction reboot_action) {
144✔
712
                                if (!reboot_action.has_value()) {
73✔
713
                                        log::Error(reboot_action.error().String());
2✔
714
                                        poster.PostEvent(StateEvent::Failure);
2✔
715
                                        return;
2✔
716
                                }
717

718
                                ctx.deployment.state_data->update_info.reboot_requested.resize(1);
71✔
719
                                ctx.deployment.state_data->update_info.reboot_requested[0] =
720
                                        NeedsRebootToDbString(*reboot_action);
71✔
721
                                switch (*reboot_action) {
71✔
722
                                case update_module::RebootAction::No:
8✔
723
                                        poster.PostEvent(StateEvent::NothingToDo);
8✔
724
                                        break;
8✔
725
                                case update_module::RebootAction::Yes:
63✔
726
                                case update_module::RebootAction::Automatic:
727
                                        poster.PostEvent(StateEvent::Success);
63✔
728
                                        break;
63✔
729
                                }
730
                        }));
73✔
731
}
73✔
732

733
void UpdateRebootState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
26✔
734
        log::Debug("Entering ArtifactReboot state");
52✔
735

736
        assert(ctx.deployment.state_data->update_info.reboot_requested.size() == 1);
737
        auto exp_reboot_mode =
738
                DbStringToNeedsReboot(ctx.deployment.state_data->update_info.reboot_requested[0]);
26✔
739
        // Should always be true because we check it at load time.
740
        assert(exp_reboot_mode);
741

742
        switch (exp_reboot_mode.value()) {
26✔
743
        case update_module::RebootAction::No:
×
744
                // Should not happen because then we don't enter this state.
745
                assert(false);
746
                poster.PostEvent(StateEvent::Failure);
×
747
                break;
748
        case update_module::RebootAction::Yes:
26✔
749
                DefaultAsyncErrorHandler(
26✔
750
                        poster,
751
                        ctx.deployment.update_module->AsyncArtifactReboot(
26✔
752
                                ctx.event_loop, DefaultStateHandler {poster}));
26✔
753
                break;
26✔
754
        case update_module::RebootAction::Automatic:
×
755
                DefaultAsyncErrorHandler(
×
756
                        poster,
757
                        ctx.deployment.update_module->AsyncSystemReboot(
×
758
                                ctx.event_loop, DefaultStateHandler {poster}));
×
759
                break;
×
760
        }
761
}
26✔
762

763
void UpdateVerifyRebootState::OnEnterSaveState(Context &ctx, sm::EventPoster<StateEvent> &poster) {
29✔
764
        log::Debug("Entering ArtifactVerifyReboot state");
58✔
765

766
        ctx.deployment.update_module->EnsureRootfsImageFileTree(
29✔
767
                ctx.deployment.update_module->GetUpdateModuleWorkDir());
58✔
768

769
        DefaultAsyncErrorHandler(
29✔
770
                poster,
771
                ctx.deployment.update_module->AsyncArtifactVerifyReboot(
29✔
772
                        ctx.event_loop, DefaultStateHandler {poster}));
29✔
773
}
29✔
774

775
void UpdateBeforeCommitState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
22✔
776
        // It's possible that the update we have done has changed our credentials. Therefore it's
777
        // important that we try to log in from scratch and do not use the token we already have.
778
        ctx.http_client.ExpireToken();
22✔
779

780
        poster.PostEvent(StateEvent::Success);
22✔
781
}
22✔
782

783
void UpdateCommitState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
19✔
784
        log::Debug("Entering ArtifactCommit state");
38✔
785

786
        // Explicitly check if state scripts version is supported
787
        auto err = script_executor::CheckScriptsCompatibility(
788
                ctx.mender_context.GetConfig().paths.GetRootfsScriptsPath());
19✔
789
        if (err != error::NoError) {
19✔
790
                log::Error("Failed script compatibility check: " + err.String());
×
791
                poster.PostEvent(StateEvent::Failure);
×
792
                return;
793
        }
794

795
        DefaultAsyncErrorHandler(
19✔
796
                poster,
797
                ctx.deployment.update_module->AsyncArtifactCommit(
19✔
798
                        ctx.event_loop, DefaultStateHandler {poster}));
38✔
799
}
800

801
void UpdateAfterCommitState::OnEnterSaveState(Context &ctx, sm::EventPoster<StateEvent> &poster) {
19✔
802
        // Now we have committed. If we had a schema update, re-save state data with the new schema.
803
        assert(ctx.deployment.state_data);
804
        auto &state_data = *ctx.deployment.state_data;
805
        if (state_data.update_info.has_db_schema_update) {
19✔
806
                state_data.update_info.has_db_schema_update = false;
×
807
                auto err = ctx.SaveDeploymentStateData(state_data);
×
808
                if (err != error::NoError) {
×
809
                        log::Error("Not able to commit schema update: " + err.String());
×
810
                        poster.PostEvent(StateEvent::Failure);
×
811
                        return;
812
                }
813
        }
814

815
        poster.PostEvent(StateEvent::Success);
19✔
816
}
817

818
void UpdateCheckRollbackState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
45✔
819
        DefaultAsyncErrorHandler(
45✔
820
                poster,
821
                ctx.deployment.update_module->AsyncSupportsRollback(
45✔
822
                        ctx.event_loop, [&ctx, &poster](expected::ExpectedBool rollback_supported) {
89✔
823
                                if (!rollback_supported.has_value()) {
45✔
824
                                        log::Error(rollback_supported.error().String());
1✔
825
                                        poster.PostEvent(StateEvent::Failure);
1✔
826
                                        return;
1✔
827
                                }
828

829
                                ctx.deployment.state_data->update_info.supports_rollback =
830
                                        SupportsRollbackToDbString(*rollback_supported);
44✔
831
                                if (*rollback_supported) {
44✔
832
                                        poster.PostEvent(StateEvent::RollbackStarted);
38✔
833
                                        poster.PostEvent(StateEvent::Success);
38✔
834
                                } else {
835
                                        poster.PostEvent(StateEvent::NothingToDo);
6✔
836
                                }
837
                        }));
45✔
838
}
45✔
839

840
void UpdateRollbackState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
41✔
841
        log::Debug("Entering ArtifactRollback state");
82✔
842

843
        DefaultAsyncErrorHandler(
41✔
844
                poster,
845
                ctx.deployment.update_module->AsyncArtifactRollback(
41✔
846
                        ctx.event_loop, DefaultStateHandler {poster}));
41✔
847
}
41✔
848

849
void UpdateRollbackRebootState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
57✔
850
        log::Debug("Entering ArtifactRollbackReboot state");
114✔
851

852
        auto exp_reboot_mode =
853
                DbStringToNeedsReboot(ctx.deployment.state_data->update_info.reboot_requested[0]);
57✔
854
        // Should always be true because we check it at load time.
855
        assert(exp_reboot_mode);
856

857
        // We ignore errors in this state as long as the ArtifactVerifyRollbackReboot state
858
        // succeeds.
859
        auto handler = [&poster](error::Error err) {
114✔
860
                if (err != error::NoError) {
57✔
861
                        log::Error(err.String());
2✔
862
                }
863
                poster.PostEvent(StateEvent::Success);
57✔
864
        };
57✔
865

866
        error::Error err;
57✔
867
        switch (exp_reboot_mode.value()) {
57✔
868
        case update_module::RebootAction::No:
869
                // Should not happen because then we don't enter this state.
870
                assert(false);
871

872
                err = error::MakeError(
×
873
                        error::ProgrammingError, "Entered UpdateRollbackRebootState with RebootAction = No");
×
874
                break;
×
875

876
        case update_module::RebootAction::Yes:
57✔
877
                err = ctx.deployment.update_module->AsyncArtifactRollbackReboot(ctx.event_loop, handler);
114✔
878
                break;
57✔
879

880
        case update_module::RebootAction::Automatic:
×
881
                err = ctx.deployment.update_module->AsyncSystemReboot(ctx.event_loop, handler);
×
882
                break;
×
883
        }
884

885
        if (err != error::NoError) {
57✔
886
                log::Error(err.String());
×
887
                poster.PostEvent(StateEvent::Success);
×
888
        }
889
}
57✔
890

891
void UpdateVerifyRollbackRebootState::OnEnterSaveState(
60✔
892
        Context &ctx, sm::EventPoster<StateEvent> &poster) {
893
        log::Debug("Entering ArtifactVerifyRollbackReboot state");
120✔
894

895
        // In this state we only retry, we don't fail. If this keeps on going forever, then the
896
        // state loop detection will eventually kick in.
897
        auto err = ctx.deployment.update_module->AsyncArtifactVerifyRollbackReboot(
898
                ctx.event_loop, [&poster](error::Error err) {
120✔
899
                        if (err != error::NoError) {
60✔
900
                                log::Error(err.String());
22✔
901
                                poster.PostEvent(StateEvent::Retry);
22✔
902
                                return;
22✔
903
                        }
904
                        poster.PostEvent(StateEvent::Success);
38✔
905
                });
60✔
906
        if (err != error::NoError) {
60✔
907
                log::Error(err.String());
×
908
                poster.PostEvent(StateEvent::Retry);
×
909
        }
910
}
60✔
911

912
void UpdateRollbackSuccessfulState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
50✔
913
        ctx.deployment.state_data->update_info.all_rollbacks_successful = true;
50✔
914
        poster.PostEvent(StateEvent::Success);
50✔
915
}
50✔
916

917
void UpdateFailureState::OnEnterSaveState(Context &ctx, sm::EventPoster<StateEvent> &poster) {
55✔
918
        log::Debug("Entering ArtifactFailure state");
110✔
919

920
        DefaultAsyncErrorHandler(
55✔
921
                poster,
922
                ctx.deployment.update_module->AsyncArtifactFailure(
55✔
923
                        ctx.event_loop, DefaultStateHandler {poster}));
55✔
924
}
55✔
925

926
static string AddInconsistentSuffix(const string &str) {
21✔
927
        const auto &suffix = main_context::MenderContext::broken_artifact_name_suffix;
928
        // `string::ends_with` is C++20... grumble
929
        string ret {str};
21✔
930
        if (!common::EndsWith(ret, suffix)) {
21✔
931
                ret.append(suffix);
21✔
932
        }
933
        return ret;
21✔
934
}
935

936
void UpdateSaveProvidesState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
75✔
937
        if (ctx.deployment.failed && !ctx.deployment.rollback_failed) {
75✔
938
                // If the update failed, but we rolled back successfully, then we don't need to do
939
                // anything, just keep the old data.
940
                poster.PostEvent(StateEvent::Success);
38✔
941
                return;
38✔
942
        }
943

944
        assert(ctx.deployment.state_data);
945
        // This state should never happen: rollback failed, but update not failed??
946
        assert(!(!ctx.deployment.failed && ctx.deployment.rollback_failed));
947

948
        // We expect Cleanup to be the next state after this.
949
        ctx.deployment.state_data->state = ctx.kUpdateStateCleanup;
37✔
950

951
        auto &artifact = ctx.deployment.state_data->update_info.artifact;
952

953
        string artifact_name;
954
        if (ctx.deployment.rollback_failed) {
37✔
955
                artifact_name = AddInconsistentSuffix(artifact.artifact_name);
38✔
956
        } else {
957
                artifact_name = artifact.artifact_name;
18✔
958
        }
959

960
        bool deploy_failed = ctx.deployment.failed;
37✔
961

962
        // Only the artifact_name and group should be committed in the case of a
963
        // failing update in order to make this consistent with the old client
964
        // behaviour.
965
        auto err = ctx.mender_context.CommitArtifactData(
37✔
966
                artifact_name,
967
                artifact.artifact_group,
37✔
968
                deploy_failed ? nullopt : optional<context::ProvidesData>(artifact.type_info_provides),
74✔
969
                /* Special case: Keep existing provides */
970
                deploy_failed ? context::ClearsProvidesData {}
93✔
971
                                          : optional<context::ClearsProvidesData>(artifact.clears_artifact_provides),
18✔
972
                [&ctx](kv_db::Transaction &txn) {
37✔
973
                        // Save the Cleanup state together with the artifact data, atomically.
974
                        return ctx.SaveDeploymentStateData(txn, *ctx.deployment.state_data);
37✔
975
                });
74✔
976
        if (err != error::NoError) {
37✔
977
                log::Error("Error saving artifact data: " + err.String());
×
978
                if (err.code
×
979
                        == main_context::MakeError(main_context::StateDataStoreCountExceededError, "").code) {
×
980
                        poster.PostEvent(StateEvent::StateLoopDetected);
×
981
                        return;
982
                }
983
                poster.PostEvent(StateEvent::Failure);
×
984
                return;
985
        }
986

987
        poster.PostEvent(StateEvent::Success);
37✔
988
}
989

990
void UpdateCleanupState::OnEnterSaveState(Context &ctx, sm::EventPoster<StateEvent> &poster) {
91✔
991
        log::Debug("Entering ArtifactCleanup state");
182✔
992

993
        // It's possible for there not to be an initialized update_module structure, if the
994
        // deployment failed before we could successfully parse the artifact. If so, cleanup is a
995
        // no-op.
996
        if (!ctx.deployment.update_module) {
91✔
997
                poster.PostEvent(StateEvent::Success);
9✔
998
                return;
9✔
999
        }
1000

1001
        DefaultAsyncErrorHandler(
82✔
1002
                poster,
1003
                ctx.deployment.update_module->AsyncCleanup(ctx.event_loop, DefaultStateHandler {poster}));
164✔
1004
}
1005

1006
void ClearArtifactDataState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
93✔
1007
        auto err = ctx.mender_context.GetMenderStoreDB().WriteTransaction([](kv_db::Transaction &txn) {
93✔
1008
                // Remove state data, since we're done now.
1009
                auto err = txn.Remove(main_context::MenderContext::state_data_key);
91✔
1010
                if (err != error::NoError) {
91✔
1011
                        return err;
×
1012
                }
1013
                return txn.Remove(main_context::MenderContext::state_data_key_uncommitted);
91✔
1014
        });
93✔
1015
        if (err != error::NoError) {
93✔
1016
                log::Error("Error removing artifact data: " + err.String());
4✔
1017
                poster.PostEvent(StateEvent::Failure);
2✔
1018
                return;
1019
        }
1020

1021
        poster.PostEvent(StateEvent::Success);
91✔
1022
}
1023

1024
void StateLoopState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
2✔
1025
        assert(ctx.deployment.state_data);
1026
        auto &artifact = ctx.deployment.state_data->update_info.artifact;
1027

1028
        // Mark update as inconsistent.
1029
        string artifact_name = AddInconsistentSuffix(artifact.artifact_name);
2✔
1030

1031
        auto err = ctx.mender_context.CommitArtifactData(
2✔
1032
                artifact_name,
1033
                artifact.artifact_group,
2✔
1034
                artifact.type_info_provides,
2✔
1035
                artifact.clears_artifact_provides,
2✔
1036
                [](kv_db::Transaction &txn) { return error::NoError; });
6✔
1037
        if (err != error::NoError) {
2✔
1038
                log::Error("Error saving inconsistent artifact data: " + err.String());
×
1039
                poster.PostEvent(StateEvent::Failure);
×
1040
                return;
1041
        }
1042

1043
        poster.PostEvent(StateEvent::Success);
2✔
1044
}
1045

1046
void EndOfDeploymentState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
93✔
1047
        log::Info(
93✔
1048
                "Deployment with ID " + ctx.deployment.state_data->update_info.id
186✔
1049
                + " finished with status: " + string(ctx.deployment.failed ? "Failure" : "Success"));
390✔
1050

1051
        ctx.FinishDeploymentLogging();
93✔
1052

1053
        ctx.deployment = {};
93✔
1054
        poster.PostEvent(
93✔
1055
                StateEvent::InventoryPollingTriggered); // Submit the inventory right after an update
93✔
1056
        poster.PostEvent(StateEvent::DeploymentEnded);
93✔
1057
        poster.PostEvent(StateEvent::Success);
93✔
1058
}
93✔
1059

1060
ExitState::ExitState(events::EventLoop &event_loop) :
96✔
1061
        event_loop_(event_loop) {
192✔
1062
}
96✔
1063

1064
void ExitState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
93✔
1065
#ifndef NDEBUG
1066
        if (--iterations_left_ <= 0) {
1067
                event_loop_.Stop();
1068
        } else {
1069
                poster.PostEvent(StateEvent::Success);
1070
        }
1071
#else
1072
        event_loop_.Stop();
93✔
1073
#endif
1074
}
93✔
1075

1076
namespace deployment_tracking {
1077

1078
void NoFailuresState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
63✔
1079
        ctx.deployment.failed = false;
63✔
1080
        ctx.deployment.rollback_failed = false;
63✔
1081
}
63✔
1082

1083
void FailureState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
60✔
1084
        ctx.deployment.failed = true;
60✔
1085
        ctx.deployment.rollback_failed = true;
60✔
1086
}
60✔
1087

1088
void RollbackAttemptedState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
52✔
1089
        ctx.deployment.failed = true;
52✔
1090
        ctx.deployment.rollback_failed = false;
52✔
1091
}
52✔
1092

1093
void RollbackFailedState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &poster) {
12✔
1094
        ctx.deployment.failed = true;
12✔
1095
        ctx.deployment.rollback_failed = true;
12✔
1096
}
12✔
1097

1098
} // namespace deployment_tracking
1099

1100
} // namespace daemon
1101
} // namespace update
1102
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc