Skip to content

nimble/host: reset resource counts in ble_gatts_reset() - #2294

Open
gmarull wants to merge 1 commit into
apache:masterfrom
teslabs:gatts-reset-counters
Open

nimble/host: reset resource counts in ble_gatts_reset()#2294
gmarull wants to merge 1 commit into
apache:masterfrom
teslabs:gatts-reset-counters

Conversation

@gmarull

@gmarull gmarull commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

ble_gatts_count_cfg() only ever adds to ble_hs_max_services, ble_hs_max_attrs and ble_hs_max_client_configs, and nothing ever resets them. ble_gatts_start() drops the added service definitions, so an application that resets the GATT server and registers its services again (host stop/start cycles, MicroPython soft reboots) has to count them again, and every cycle grows the pools allocated by ble_att_svr_start() and ble_gatts_start(). The only way to avoid the leak today is to poke the ble_hs_priv.h counters from application code.

Clear the counters in ble_gatts_reset(), together with any service definitions added but not yet started (they would otherwise fail to register against zero-sized pools), so the server really returns to its initial state and the next count/add/start sequence sizes the pools from scratch. The test helper is adjusted, as it relied on the counts preset by ble_hs_test_util_init() surviving the reset.

Fixes #896

ble_gatts_count_cfg() only ever adds to ble_hs_max_services,
ble_hs_max_attrs and ble_hs_max_client_configs, and nothing ever
resets them. ble_gatts_start() drops the added service definitions,
so an application that resets the GATT server and registers its
services again (host stop/start cycles, MicroPython soft reboots) has
to count them again, and every cycle grows the pools allocated by
ble_att_svr_start() and ble_gatts_start(). The only way to avoid the
leak today is to poke the ble_hs_priv.h counters from application
code.

Clear the counters in ble_gatts_reset(), together with any service
definitions added but not yet started (they would otherwise fail to
register against zero-sized pools), so the server really returns to
its initial state and the next count/add/start sequence sizes the
pools from scratch. Adjust the test helper, which relied on the
counts preset by ble_hs_test_util_init() surviving the reset.

Fixes apache#896

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service re-registration leads to increasingly large allocs

1 participant