Draft
Fix daemon stopping error during LXD container initialization#871
Conversation
- Add exponential backoff retry logic (5 attempts, 1-16 seconds) - Detect "daemon is stopping" error in stderr - Add comprehensive unit tests for retry scenarios - Tests cover: successful retry, retry exhaustion, non-transient errors Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
- Move time import to module level - Fix trailing whitespace in test files - Apply ruff formatting Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Add explicit comment showing wait time progression: 1s, 2s, 4s, 8s, 16s Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copilot stopped work on behalf of
lengau due to an error
December 8, 2025 22:06
Collaborator
|
@copilot boop |
Collaborator
|
@copilot Kindly do the needful |
Contributor
Author
I've removed the [WIP] tag from the PR. The implementation is complete with: ✅ Retry logic with exponential backoff (1s, 2s, 4s, 8s, 16s) The PR is ready for final review and merge. |
Copilot
AI
changed the title
[WIP] Fix daemon stopping error during LXD container initialization
Fix daemon stopping error during LXD container initialization
Dec 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make lint && make test?Description
This PR fixes the intermittent "daemon is stopping to wait for socket activation" error that occurs during LXD container initialization when craft-providers attempts to wait for snap refreshes.
Problem
When creating and initializing LXD base containers, craft-providers fails with "daemon is stopping to wait for socket activation" error when running
snap watch --last=auto-refresh?. This indicates that snapd inside the newly created container is in a transitional state and not yet ready to handle the command, causing the entire container setup to fail intermittently.Solution
Implemented retry logic with exponential backoff in the
_disable_and_wait_for_snap_refreshmethod to gracefully handle transient snapd states:Changes Made
Core Implementation
craft_providers/base.py:
timemodule import_disable_and_wait_for_snap_refreshto implement retry logic with exponential backoffTests
Added comprehensive unit tests covering all retry scenarios:
Tests added to:
tests/unit/bases/test_ubuntu_buildd.py(3 new tests)tests/unit/bases/test_almalinux.py(3 new tests)tests/unit/bases/test_centos_7.py(3 new tests)Testing
Impact
This fix addresses:
The solution is minimal and surgical, only adding retry logic for the specific transient error without changing the overall flow or behavior for other error conditions.
Original prompt
This section details on the original issue you should resolve
<issue_title>snapd "daemon is stopping to wait for socket activation" error during LXD container initialization</issue_title>
<issue_description>### Bug Description
When craft-providers creates and initializes LXD base containers, it fails with "daemon is stopping to wait for socket activation" error when attempting to wait for snap refreshes. This causes builds to fail intermittently.
To Reproduce
Environment
craft_providers.base._disable_and_wait_for_snap_refreshSteps to Reproduce
snap watch --last=auto-refresh?Expected Behavior
The container should be created successfully, with snapd fully initialized and ready to handle snap operations.
Actual Behavior
The command fails with:
Error Details
Error message:
Full stack trace:
Root Cause Analysis
The error "daemon is stopping to wait for socket activation" indicates that snapd inside the newly created container is in a transitional state. This typically happens when:
The current code in
craft_providers.base._disable_and_wait_for_snap_refresh()(around line 616) doesn't handle this transient state, causing the entire container setup to fail.Impact
Proposed Solutions
Option 1: Add retry logic with exponential backoff (Recommended)
Modify
_disable_and_wait_for_snap_refreshto retry when encountering the "daemon is stopping" error: