Azure / Azure/iot-hub-device-update

Intermittent SIGSEGV in ld.so during agent shutdown (dlsym on unloaded content downloader)

Open Beginner friendly
#908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
61
Forks
54
Avg merge
2d 15h
Merged PRs (30d)
1

Description

Summary

AducIotAgent intermittently crashes with SIGSEGV inside the dynamic loader
(ld-linux.so) during shutdown. Exit-only — the agent restarts fine, but
systemd records the stop as core-dump. Seen on aarch64, 1.4.0.

Root cause

ExtensionManager::Uninit() runs twice during shutdown:

  • via AzureDeviceUpdateCoreInterface_Destroy (linux_adu_core_impl.cpp, from
    ADUC_PnP_Components_Destroy), and
  • via ExtensionManager_Uninit() in the agent's ShutdownAgent (main.c).

ExtensionManager::UnloadAllExtensions() dlcloses the content-downloader
library (in _libs) and clears _libs, but never resets the static
_contentDownloader handle or _contentDownloaderContractVersion. So the second
call still sees _contentDownloader != nullptr and a V2 contract, and runs
dlsym(_contentDownloader, "Cleanup") on the freed handle. glibc's
do_lookup_x then walks a freed link_map → intermittent SEGV_MAPERR
(intermittent because the freed memory is sometimes still mapped).

Symbolized crashing stack (from a device core):

do_lookup_x (undef_name="Cleanup", undef_map=<freed link_map>)   ld.so
_dl_lookup_symbol_x -> do_sym -> _dl_sym -> ___dlsym
ExtensionManager::UnloadAllExtensions()  extension_manager.cpp:418
ShutdownAgent -> ExtensionManager_Uninit
Reproduces when

A V2-contract content downloader is loaded (curl is the default in 1.4.0) and
the agent is stopped (SIGTERM) — e.g. during an OS update. Intermittent.

Fix

Reset _contentDownloader and _contentDownloaderContractVersion after the
dlclose loop in UnloadAllExtensions() so a repeat Uninit is a no-op. PR
attached.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in extension_manager.cpp at UnloadAllExtensions(), around line 418, and trace the shutdown paths through linux_adu_core_impl.cpp and main.c. Verify that repeated Uninit calls no longer use the unloaded content-downloader handle; done means SIGTERM shutdown does not reach dlsym with a freed handle.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.