Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wifi-remote]: Fix server race when receiving command and posting events #582

Merged

Conversation

david-cermak
Copy link
Collaborator

Fixes race condition of simultaneously marshaling WiFi/IP event and receiving command from client.

  • 9e13870 fix(wifi_remote): Lock server before marshaling events --> Quick and simple fix, but may block default event task
  • 30a5262 Fix server event/command race condition using eventfd --> More elaborate and correct fix

@david-cermak david-cermak force-pushed the fix/wifi_remote_server_sync branch from 30a5262 to 732b1d5 Compare May 31, 2024 05:55
ip_data = new (std::nothrow) esp_wifi_remote_eppp_ip_event;
return ip_data ? ESP_OK : ESP_ERR_NO_MEM;
}
~Events()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain the usage you expect here? The struct has only default constructed data and depending on state the destructor might leak the allocated ip_data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea is using RAII even when en-queuing and later de-queuing the instance.

the destructor might leak the allocated ip_data.

  • we construct ip_data only when needed (if we get the appropriate IP_EVENT)
  • we put this instance to the queue and only after (successful) en-queuing we mark this as DO-NOT-FREE, so the desctructor leaks the data, as they will be used afterwards...
  • we get the instance from the queue with the default state, so now the destructor frees the data as expected

(briefly commented here https://github.com/espressif/esp-protocols/pull/582/files#diff-e2d9eebe2ae3236f3c8b216ed4f69dd878089e5f7c1b2fe3fb9a23c238651b8fR61)

0.2.3
Bug Fixes
- Fix server event/command race condtion using eventfd (732b1d5)
- Lock server before marshalling events (9e13870)
@david-cermak david-cermak merged commit 39d5903 into espressif:master Jun 5, 2024
32 checks passed
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.

2 participants