Skip to content

feat(websocket): add task-preserving pause/resume lifecycle and websocket feature showcase docs/example (IDFGH-17329)#1023

Open
633k4hire wants to merge 10 commits intoespressif:masterfrom
633k4hire:master
Open

feat(websocket): add task-preserving pause/resume lifecycle and websocket feature showcase docs/example (IDFGH-17329)#1023
633k4hire wants to merge 10 commits intoespressif:masterfrom
633k4hire:master

Conversation

@633k4hire
Copy link

@633k4hire 633k4hire commented Mar 4, 2026

Description

This PR combines API/runtime improvements in esp_websocket_client with updated documentation and a comprehensive feature-showcase example.

It introduces a task-preserving pause/resume lifecycle for reconnect-heavy deployments, and updates docs/examples to make newer websocket capabilities easier to adopt correctly.

Motivation / Context

In long-running embedded deployments with frequent reconnects, repeated stop/start cycles tear down and recreate websocket task/transport resources. Over time, this can increase allocation churn and contribute to heap instability/fragmentation patterns.

To improve runtime stability, this PR adds an explicit park-and-resume path:

  • temporarily close transport,
  • keep websocket task alive,
  • reconnect without task recreation.

At the same time, the PR improves discoverability of modern websocket APIs through refreshed docs and a dedicated, copy-pasteable example.

What changed

1) New pause/resume lifecycle support

  • Added public APIs:
    • esp_websocket_client_pause()
    • esp_websocket_client_resume()
  • Added API docs and usage constraints.
  • Extended internal state/event handling to support safe parked/resume flow:
    • paused state support
    • resume/wake signaling path
  • Implemented behavior:
    • pause() closes transport and transitions client to paused state.
    • resume() can optionally refresh headers and trigger reconnect.
    • task loop blocks while paused (no busy polling) and resumes through reconnect init path.
  • Hardened abort handling to treat paused clients as non-active in abort path.

2) Compatibility and API behavior hardening

  • Added backward-compat send shim:
    • esp_websocket_client_send() forwarding to binary send behavior.
  • Added unit-test coverage for pause/resume API contract checks:
    • null argument validation
    • behavior when initialized but not started

3) Docs + example improvements (feature discoverability)

  • Updated websocket component README highlights and links.
  • Updated docs/esp_websocket_client/en/index.rst with recent capabilities, including header callback event visibility and showcase link.
  • Added new top-level example:
    • examples/websocket_features
    • includes README.md, CMakeLists.txt, Kconfig.projbuild, idf_component.yml, and fully commented main/app_main.c
    • demonstrates:
      • header callbacks
      • custom headers
      • fragmented frame APIs
      • pause/resume lifecycle
      • runtime ping/reconnect tuning
      • lifecycle + heap observability logs

Related

  • Related docs: esp_websocket_client API documentation

Testing

  • Added/updated unit coverage for pause/resume validation paths.
  • Verified example/docs updates and integration wiring for new showcase app.

Checklist

  • 🚨 This PR does not introduce breaking changes.
  • Relevant checks pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Note

Medium Risk
Medium risk because it changes the websocket client task state machine/event-bit waits and connection abort behavior, which could impact reconnect/close flows and concurrency edge cases. Docs/examples/test additions are low risk, but the runtime lifecycle changes warrant careful review on real devices.

Overview
Adds new public APIs esp_websocket_client_pause() and esp_websocket_client_resume() that close the transport but keep the websocket FreeRTOS task alive, introducing a new WEBSOCKET_STATE_PAUSED plus RESUME_BIT/WAKE_BIT signaling so the task can park at zero CPU and later re-initiate a connection.

Improves compatibility by adding ESP-IDF 4.4 shims for missing ws-transport helpers and restoring the legacy esp_websocket_client_send() symbol (binary default), while extending unit tests to cover pause/resume argument and not-started behavior.

Refreshes documentation/readmes to highlight newer features (header callback, redirects, fragmentation, pause/resume) and adds a new examples/websocket_features reference app demonstrating these capabilities with logging and heap observability.

Written by Cursor Bugbot for commit ba2f186. This will update automatically on new commits. Configure here.

@CLAassistant
Copy link

CLAassistant commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Free Tier Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bugbot Autofix is kicking off a free cloud agent to fix these issues. This run is complimentary, but you can enable autofix for all future PRs in the Cursor dashboard.

ESP_LOGI(TAG, "Resume requested");
return ESP_OK;
}

Copy link

Choose a reason for hiding this comment

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

Removed .auth field breaks HTTP Basic Authentication

High Severity

The .auth = client->config->auth line was removed from the esp_transport_ws_config_t initialization in set_websocket_transport_optional_settings(). The auth field is computed from username/password via http_auth_basic() and stored in client->config->auth, but it's no longer passed to the transport layer. This silently breaks HTTP Basic Authentication for all websocket connections that use username/password credentials.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

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

Bugbot Autofix determined this is a false positive.

The websocket transport configuration already includes .auth = client->config->auth, so Basic Auth credentials are still propagated correctly.

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

} else {
xEventGroupSetBits(client->status_bits, STOPPED_BIT);
}
ESP_LOGI(TAG, "[DIAG] websocket_task calling vTaskDelete(NULL) tick=%lu", (unsigned long)xTaskGetTickCount());
Copy link

Choose a reason for hiding this comment

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

Diagnostic debug log accidentally left in production code

Low Severity

The [DIAG] prefixed ESP_LOGI log line printing tick count before vTaskDelete appears to be development-time diagnostic code that was not removed before submission. It adds noise to production logs and uses a non-standard [DIAG] prefix not found elsewhere in the codebase.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

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

Bugbot Autofix determined this is a false positive.

No [DIAG] ESP_LOGI line before vTaskDelete(NULL) is present in the current source, so there is no diagnostic log to remove.

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

int esp_websocket_client_send(esp_websocket_client_handle_t client, const char *data, int len, TickType_t timeout)
{
return esp_websocket_client_send_bin(client, data, len, timeout);
}
Copy link

Choose a reason for hiding this comment

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

Re-adds previously removed deprecated API function

Medium Severity

esp_websocket_client_send() was intentionally deprecated and removed in an earlier release (documented in CHANGELOG.md as "removed deprecated API"). This PR re-introduces it as a backward-compat shim. Re-adding a function that was deliberately removed creates confusion about the API surface and contradicts the project's prior deprecation decision.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

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

Bugbot Autofix determined this is a false positive.

The deprecated esp_websocket_client_send() API is not declared or defined in the current codebase, so it has not been reintroduced.

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@github-actions github-actions bot changed the title feat(websocket): add task-preserving pause/resume lifecycle and websocket feature showcase docs/example feat(websocket): add task-preserving pause/resume lifecycle and websocket feature showcase docs/example (IDFGH-17329) Mar 4, 2026
@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants