Skip to content

fix(websocket): fix setup logic in the external transport (IDFGH-15250)#811

Closed
huming2207 wants to merge 0 commit intoespressif:masterfrom
huming2207:master
Closed

fix(websocket): fix setup logic in the external transport (IDFGH-15250)#811
huming2207 wants to merge 0 commit intoespressif:masterfrom
huming2207:master

Conversation

@huming2207
Copy link
Contributor

@huming2207 huming2207 commented May 7, 2025

Description

Hi all,

I made a dumb mistake when I was submitting the PR: #573

I somehow forgot two branch logic when setting up the websocket client transport. These two logic exist in our company's codebase and we have used it for a year already, but somehow was missing in the PR to this upstream codebase. Without these two conditions, the websocket client will create a esp_transport handle anyhow, no matter the ext_transport was provided or not. This will break the proxy support of course.

Anyway, here's the fix. Sorry again for the trouble I made.

Regards,
Jackson

Related

PR related:

Testing

These two logic exist in our company's codebase and we have used it for a year already in our products.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) 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.

@huming2207 huming2207 marked this pull request as draft May 7, 2025 00:34
@huming2207
Copy link
Contributor Author

Sorry, we internally reviewed and we think we have more issues to fix. I will fix it first and then let you know we are ready.

@github-actions github-actions bot changed the title fix(websocket): add missing logics on setting up external transport fix(websocket): add missing logics on setting up external transport (IDFGH-15250) May 7, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 7, 2025
@huming2207 huming2207 marked this pull request as ready for review May 7, 2025 02:50
@huming2207
Copy link
Contributor Author

Okay now I'm ready for review.

This also fixes some potential memory corruptions. Previously if I use an externally created proxy handle that is not a transport_ssl or transport_tcp handle, and if some options like keep alive was set, the esp_transport_ssl_set_*() will be called and eventually corrupts the proxy handle context. Because the type is different.

@huming2207 huming2207 changed the title fix(websocket): add missing logics on setting up external transport (IDFGH-15250) fix(websocket): fix setup logic in the external transport (IDFGH-15250) May 7, 2025
@huming2207
Copy link
Contributor Author

Hello @glmfe , may I ask is there any feedback on this PR?

@huming2207
Copy link
Contributor Author

Any updates...? @glmfe

@huming2207
Copy link
Contributor Author

Hello......??

@euripedesrocha
Copy link
Collaborator

Hi @huming2207, thanks for the contribution, and sorry for the delay.

I need to double-check the code because we shouldn't be reaching that logic.

Second and most important, when adding the external transport we should be adding the full transport, not only the parent. To be honest, I'm undecided on what is more confusing to users.

At this point, I believe that the simple approach is that the external transport must be the full transport implementation, not only the parent for transport_ws.

@huming2207
Copy link
Contributor Author

Hi @euripedesrocha

Thanks for the followup.

I need to double-check the code because we shouldn't be reaching that logic.

Nah I think the original implementation has already caused us heap corruptions.

At this point, I believe that the simple approach is that the external transport must be the full transport implementation, not only the parent for transport_ws.

Yea, and the original implementation will simply doesn't work and cause memory corruptions. I think we need something that actually work at least... 😅

Jackson

@euripedesrocha
Copy link
Collaborator

@huming2207 I would like to understand your problem here.

The original version of this feature seems to take the correct approach.

When adding an external transport, I expect that the user needs to set all parameters of the transport and the library should work with what was added. For this library it means that you need to initialize the parent and pass it to websocket_ts or even implement the base transport completely. I agree that the first case of adding the parent is the most common.

Can you share a small reproducer that causes the memory corruption?

@huming2207
Copy link
Contributor Author

huming2207 commented Jun 26, 2025

Sorry @euripedesrocha I was a bit busy earlier as well 😅

When adding an external transport, I expect that the user needs to set all parameters of the transport and the library should work with what was added. For this library it means that you need to initialize the parent and pass it to websocket_ts or even implement the base transport completely. I agree that the first case of adding the parent is the most common.

Can you share a small reproducer that causes the memory corruption?

Ah yes I think you are right. I misread the code and the esp_transport_tcp_set_***() won't apply to the external transport because I already have a guard here anyway:

But yes for fb22749 , This one I think is necessary. Otherwise it won't actually use my external transport at all.

Sorry for the trouble. I will remove this commit: 76b475e

EDIT: I will recheck a bit later. I think I misread something badly.

@huming2207 huming2207 force-pushed the master branch 2 times, most recently from 5e3c4cc to f10790f Compare June 26, 2025 08:30
@huming2207
Copy link
Contributor Author

huming2207 commented Jun 26, 2025

Done. Could you please check again? Thanks! @euripedesrocha

No sorry I think I misread my code again. Let me recheck a bit later. I think both commits are actually necessary. I'm now busy fixing some other bugs and I will re-address this issue maybe tomorrow or early next week.

@huming2207
Copy link
Contributor Author

Sorry I will come back on this a bit later. I think I might did something wrong in the beginning. I will come back to this maybe next week after I fix some other urgent issues.

@huming2207
Copy link
Contributor Author

Hi @euripedesrocha

I think I know why now. I think our company's esp-websocket-client codebase probably somehow messed up and missing the patch from this PR: #616

Thus you were indeed correct, there's probably no issue from the beginning. Sorry for the trouble...😅

I will close this PR for now and I will test again tomorrow. If we find something new I will open a new discussion and provide more details.

Regards,
Jackson

@euripedesrocha
Copy link
Collaborator

@huming2207 thanks for taking a look! If you can provide a small sample on how you are using the feature, is also useful for me to understand how to address expectations and document better.

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.

4 participants