Skip to content

fix(ether): harden asynchronous shutdown and timer lifetime - #592

Open
luisgutierrezpereda wants to merge 1 commit into
mainfrom
fix/SENDESK-147-ether-crash
Open

luisgutierrezpereda wants to merge 1 commit into
mainfrom
fix/SENDESK-147-ether-crash

Conversation

@luisgutierrezpereda

Copy link
Copy Markdown
Collaborator

Keep the ASIO io_context alive until its executor exits, preventing shutdown from destroying scheduler state while io_context::run() is still active.

Synchronize timer creation with context teardown and avoid retaining references to timer-map entries that may be erased concurrently. Make pending accept callbacks retain their acceptor and explicitly stop accepting during shutdown. Also ensure destruction performs final transport cleanup.

Add regression tests covering shutdown from the executor thread, shutdown while a handler is running with additional work queued, and timer creation, cancellation, and expiry racing with shutdown.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/2)

config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
}

Configuration config_ = makeConfiguration();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable config_ has protected visibility

Comment on lines +43 to +44
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member config_

Suggested change
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))
: discovery_(DiscoverySystem::make(config, discoveryIo_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config, exclusions_))

[[nodiscard]] std::unique_ptr<EtherTransport> makeTransport() const
{
return std::make_unique<EtherTransport>(
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member config_

Suggested change
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
config, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);

config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
}

Configuration config_ = makeConfiguration();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member config_

Suggested change
Configuration config_ = makeConfiguration();
Configuration config = makeConfiguration();

}

Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable exclusions_ has protected visibility

protected:
EtherTransportTest()
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member exclusions_

Suggested change
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions))

[[nodiscard]] std::unique_ptr<EtherTransport> makeTransport() const
{
return std::make_unique<EtherTransport>(
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member exclusions_

Suggested change
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions, runtimeFootprint_);

}

Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member exclusions_

Suggested change
NetworkExclusions exclusions_;
NetworkExclusions exclusions;


Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;
asio::io_context discoveryIo_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable discoveryIo_ has protected visibility

{
protected:
EtherTransportTest()
: discovery_(DiscoverySystem::make(config_, discoveryIo_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member discoveryIo_

Suggested change
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
: discovery_(DiscoverySystem::make(config_, discoveryIo))

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (2/2)


Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;
asio::io_context discoveryIo_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member discoveryIo_

Suggested change
asio::io_context discoveryIo_;
asio::io_context discoveryIo;

Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;
asio::io_context discoveryIo_;
std::shared_ptr<DiscoverySystem> discovery_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable discovery_ has protected visibility

{
protected:
EtherTransportTest()
: discovery_(DiscoverySystem::make(config_, discoveryIo_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member discovery_

Suggested change
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
: discovery(DiscoverySystem::make(config_, discoveryIo_))

[[nodiscard]] std::unique_ptr<EtherTransport> makeTransport() const
{
return std::make_unique<EtherTransport>(
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member discovery_

Suggested change
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
config_, "etherTransportTest", "etherTransportTest", discovery, nullptr, exclusions_, runtimeFootprint_);

Configuration config_ = makeConfiguration();
NetworkExclusions exclusions_;
asio::io_context discoveryIo_;
std::shared_ptr<DiscoverySystem> discovery_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member discovery_

Suggested change
std::shared_ptr<DiscoverySystem> discovery_;
std::shared_ptr<DiscoverySystem> discovery;

NetworkExclusions exclusions_;
asio::io_context discoveryIo_;
std::shared_ptr<DiscoverySystem> discovery_;
std::shared_ptr<RuntimeNetworkFootprintState> runtimeFootprint_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable runtimeFootprint_ has protected visibility

protected:
EtherTransportTest()
: discovery_(DiscoverySystem::make(config_, discoveryIo_))
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member runtimeFootprint_

Suggested change
, runtimeFootprint_(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))
, runtimeFootprint(std::make_shared<RuntimeNetworkFootprintState>(config_, exclusions_))

[[nodiscard]] std::unique_ptr<EtherTransport> makeTransport() const
{
return std::make_unique<EtherTransport>(
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member runtimeFootprint_

Suggested change
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint_);
config_, "etherTransportTest", "etherTransportTest", discovery_, nullptr, exclusions_, runtimeFootprint);

NetworkExclusions exclusions_;
asio::io_context discoveryIo_;
std::shared_ptr<DiscoverySystem> discovery_;
std::shared_ptr<RuntimeNetworkFootprintState> runtimeFootprint_;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ readability-identifier-naming ❌
invalid case style for protected member runtimeFootprint_

Suggested change
std::shared_ptr<RuntimeNetworkFootprintState> runtimeFootprint_;
std::shared_ptr<RuntimeNetworkFootprintState> runtimeFootprint;

#include <memory>
#include <mutex>
#include <thread>
#include <vector>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-include-cleaner ❌
no header providing "std::ignore" is directly included

Suggested change
#include <vector>
#include <tuple>
#include <vector>

Keep the ASIO io_context alive until its executor exits, preventing shutdown
from destroying scheduler state while io_context::run() is still active.

Synchronize timer creation with context teardown and avoid retaining references
to timer-map entries that may be erased concurrently. Make pending accept
callbacks retain their acceptor and explicitly stop accepting during shutdown.
Also ensure destruction performs final transport cleanup.

Add regression tests covering shutdown from the executor thread, shutdown while
a handler is running with additional work queued, and timer creation,
cancellation, and expiry racing with shutdown.
@luisgutierrezpereda
luisgutierrezpereda force-pushed the fix/SENDESK-147-ether-crash branch from 427a252 to c3e2b7c Compare November 17, 2026 22:06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant