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

socket leak? #1

Closed
jvatic opened this issue Jun 3, 2024 · 2 comments
Closed

socket leak? #1

jvatic opened this issue Jun 3, 2024 · 2 comments

Comments

@jvatic
Copy link

jvatic commented Jun 3, 2024

While I know this crate is experimental and in active development, I'm attempting to use it for an esp32s3 project since using async-io results in stack overflows I'm not able to avoid.

async-io-mini works great for the first 9 (CONFIG_LWIP_MAX_SOCKETS-1) calls to Async::<TcpStream>::connect, and then panics on the 10th:

thread '<unnamed>' panicked at /Users/jesse/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/os/fd/owned.rs:165:9:
assertion `left != right` failed
  left: -1
 right: -1

(If I increase CONFIG_LWIP_MAX_SOCKETS to the maximum of 16, then it will fail on the 15th iteration. I'm assuming the other socket is being used for wifi.)

I've confirmed this only occurs when using this crate with a modified version of the esp-idf-svc tls_async example: https://gist.github.com/jvatic/2ad238eb05dbe60919f7cfa338085c15. Using async-io it will either stack overflow or run 10 successful iterations, and using async-io-mini it will run 9 successful iterations before exiting with the above panic on the 10th.

Is this an issue you're aware of? I've poked around to try and see why the sockets aren't being released without much luck so far, so thought I'd ask. (And I'm happy to contribute if you can point me in the right direction!)

I've tried calling libc::shutdown and libc::close directly with the fd (from Async::<TcpStream>::into_inner().unwrap().into_raw_fd()) at the end of the loop in an attempt to mimic this c example, but that doesn't resolve the apparent socket leak.

@ivmarkov
Copy link
Owner

ivmarkov commented Jun 3, 2024

Thanks for the bug report! I've fixed it, so if you cargo update it should work for you now.

The bug was a pretty noob-style one, but oh well, I guess such is life.

W.r.t. stack blowups with async-io, you could avoid those, if:

  • You setup CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192 in your sdkconfig.defaults
  • (Temporarily, and only for xtensa MCUs) use async-io = "=2.0.0" (notice the exact syntax), because of this
  • Initialize/allocate its thread reactor early, ideally outside of your main async loop, for example using this hack

@jvatic
Copy link
Author

jvatic commented Jun 3, 2024

Wonderful, thank you for the fix and info! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants