Skip to content

Commit db06b19

Browse files
authored
Merge pull request #1137 from david-cermak/fix/mdns_browse_sync_end_race
fix(mdns): Fix mdns browse SYNC vs. END race
2 parents 4b20d08 + da126db commit db06b19

7 files changed

Lines changed: 70 additions & 6 deletions

File tree

.github/workflows/mdns__build-target-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Build
1414
strategy:
1515
matrix:
16-
idf_ver: ["latest", "release-v5.0", "release-v5.2", "release-v5.3"]
16+
idf_ver: ["latest", "release-v5.5", "release-v6.0", "release-v6.1"]
1717
test: [ { app: example, path: "examples/query_advertise" }, { app: unit_test, path: "tests/unit_test" }, { app: test_app, path: "tests/test_apps" } ]
1818
runs-on: ubuntu-22.04
1919
container: espressif/idf:${{ matrix.idf_ver }}
@@ -24,7 +24,7 @@ jobs:
2424
shell: bash
2525
run: |
2626
. ${IDF_PATH}/export.sh
27-
if [[ "${{ matrix.idf_ver }}" == "latest" ]]; then
27+
if [[ "${{ matrix.idf_ver }}" == "latest" || "${{ matrix.idf_ver }}" == release-v6.* ]]; then
2828
export EXPECTED_WARNING="warning: unknown kconfig symbol 'EXAMPLE_ETH_PHY_IP101'"
2929
else
3030
export EXPECTED_WARNING="warning: unknown kconfig symbol 'EXAMPLE_ETH_PHY_GENERIC'"

.github/workflows/mdns__host-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ jobs:
1111
host_test_mdns:
1212
if: contains(github.event.pull_request.labels.*.name, 'mdns') || github.event_name == 'push'
1313
name: Host test build
14+
strategy:
15+
matrix:
16+
idf_ver: ["latest", "release-v5.3", "release-v5.4", "release-v5.5"]
1417
runs-on: ubuntu-22.04
15-
container: espressif/idf:release-v5.3
18+
container: espressif/idf:${{ matrix.idf_ver }}
1619

1720
steps:
1821
- name: Checkout esp-protocols

components/mdns/.cz.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ commitizen:
33
bump_message: 'bump(mdns): $current_version -> $new_version'
44
pre_bump_hooks: python ../../ci/changelog.py mdns
55
tag_format: mdns-v$version
6-
version: 1.11.3
6+
version: 1.12.0
77
version_files:
88
- idf_component.yml

components/mdns/CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Changelog
22

3+
## [1.12.0](https://github.com/espressif/esp-protocols/commits/mdns-v1.12.0)
4+
5+
### Features
6+
7+
- add hostname change callback ([c2cd90b0](https://github.com/espressif/esp-protocols/commit/c2cd90b0))
8+
- Make mDNS browse feature optional ([2e0c2540](https://github.com/espressif/esp-protocols/commit/2e0c2540))
9+
10+
### Bug Fixes
11+
12+
- Update supported/tested IDF version matrix ([e8427217](https://github.com/espressif/esp-protocols/commit/e8427217))
13+
- Fix mdns browse SYNC vs. END race ([1b83e978](https://github.com/espressif/esp-protocols/commit/1b83e978))
14+
- Only depend on esp_wifi when Wi-Fi is enabled ([47724b7d](https://github.com/espressif/esp-protocols/commit/47724b7d), [#835](https://github.com/espressif/esp-protocols/issues/835))
15+
- Update host test to check goodbye and browse dupl ([ab03980d](https://github.com/espressif/esp-protocols/commit/ab03980d))
16+
- Fix mdns_browse_new() return dangling pointer on duplicated browsers ([e063449c](https://github.com/espressif/esp-protocols/commit/e063449c))
17+
- Create static task only when SPIRAM-task-alloc is ON ([6f31f27f](https://github.com/espressif/esp-protocols/commit/6f31f27f))
18+
- validate subtype label position ([a09b24fe](https://github.com/espressif/esp-protocols/commit/a09b24fe))
19+
- ignore subtype SRV and TXT questions ([7910501d](https://github.com/espressif/esp-protocols/commit/7910501d))
20+
- distinguish subtype queries from instances ([b9103169](https://github.com/espressif/esp-protocols/commit/b9103169))
21+
- Don't free a browse result already freed by an earlier sync batch ([9057f2d9](https://github.com/espressif/esp-protocols/commit/9057f2d9))
22+
23+
### Updated
24+
25+
- test(mdns): add hostname callback target test ([4c8b76dd](https://github.com/espressif/esp-protocols/commit/4c8b76dd))
26+
- test(mdns): add hostname callback host test ([1f35d5f3](https://github.com/espressif/esp-protocols/commit/1f35d5f3))
27+
- test(mdns): cover subtype query handling ([c14ed4fc](https://github.com/espressif/esp-protocols/commit/c14ed4fc))
28+
- refactor(mdns): share debug name formatting ([8c7bc865](https://github.com/espressif/esp-protocols/commit/8c7bc865))
29+
330
## [1.11.3](https://github.com/espressif/esp-protocols/commits/mdns-v1.11.3)
431

532
### Features

components/mdns/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.11.3"
1+
version: "1.12.0"
22
description: "Multicast UDP service used to provide local network service and host discovery."
33
url: "https://github.com/espressif/esp-protocols/tree/master/components/mdns"
44
issues: "https://github.com/espressif/esp-protocols/issues"

components/mdns/mdns_browser.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ static void browse_item_free(mdns_browse_t *browse)
5656
mdns_mem_free(browse);
5757
}
5858

59+
/**
60+
* @brief Check that a browse is still linked in @c s_browse
61+
*
62+
* Sync batches borrow @c browse_sync->browse. ACTION_BROWSE_END may detach and
63+
* free that browse while a later ACTION_BROWSE_SYNC is still queued, so the
64+
* sync handler must not touch the pointer without checking.
65+
*/
66+
static bool browse_is_in_list(const mdns_browse_t *browse)
67+
{
68+
for (const mdns_browse_t *b = s_browse; b != NULL; b = b->next) {
69+
if (b == browse) {
70+
return true;
71+
}
72+
}
73+
return false;
74+
}
75+
5976
/**
6077
* @brief Check that a result node is still linked in the browse cache
6178
*
@@ -85,6 +102,10 @@ static bool result_is_cached(const mdns_browse_t *browse, const mdns_result_t *r
85102
static void browse_sync(mdns_browse_sync_t *browse_sync)
86103
{
87104
mdns_browse_t *browse = browse_sync->browse;
105+
// END may have already detached+freed this browse, or delete marked it off
106+
if (!browse_is_in_list(browse) || browse->state != BROWSE_RUNNING) {
107+
return;
108+
}
88109
mdns_browse_result_sync_t *sync_result = browse_sync->sync_result;
89110
while (sync_result) {
90111
mdns_result_t *result = sync_result->result;

components/mdns/tests/host_test/main/main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
66
#include <stdio.h>
7+
#include <stdlib.h>
8+
#include "esp_idf_version.h"
79
#include "esp_log.h"
810
#include "freertos/FreeRTOS.h"
911
#include "freertos/task.h"
@@ -20,8 +22,15 @@ static EventGroupHandle_t s_exit_signal = NULL;
2022

2123
static int exit_console(int argc, char **argv)
2224
{
25+
#ifdef CONFIG_IDF_TARGET_LINUX
26+
/* Host tests do not need graceful REPL teardown; exit hard so leftover
27+
* console_repl / linenoise threads cannot keep the process alive. */
28+
ESP_LOGI(TAG, "Exit");
29+
exit(0);
30+
#else
2331
xEventGroupSetBits(s_exit_signal, 1);
2432
return 0;
33+
#endif
2534
}
2635

2736
#else
@@ -109,12 +118,16 @@ static void mdns_test_app(esp_netif_t *interface)
109118
#ifdef CONFIG_TEST_CONSOLE
110119
esp_console_repl_t *repl = NULL;
111120
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
112-
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
113121
s_exit_signal = xEventGroupCreate();
114122

115123
repl_config.prompt = "mdns>";
116124
// init console REPL environment
125+
#if CONFIG_IDF_TARGET_LINUX && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 1, 0)
126+
ESP_ERROR_CHECK(esp_console_new_repl_stdio(&repl_config, &repl));
127+
#else
128+
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
117129
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
130+
#endif
118131

119132
const esp_console_cmd_t cmd_exit = {
120133
.command = "exit",

0 commit comments

Comments
 (0)