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

mbedtls_net_set_nonblock / mbedtls_net_set_block doesn't work (IDFGH-2264) #4407

Closed
szmodz opened this issue Nov 26, 2019 · 5 comments
Closed

Comments

@szmodz
Copy link

szmodz commented Nov 26, 2019

Latest master (93a8603) using 2019r2 toolchain.

mbedtls_net_set_nonblock / mbedtls_net_set_block doesn't work.

Steps to reproduce: try using mbedtls_net_set_nonblock / mbedtls_net_set_block

Apparently it's because HAVE_FCNTL was not defined when building the C library.

https://github.com/espressif/newlib-esp32/blob/esp_based_on_3_0_0/newlib/libc/syscalls/sysfcntl.c

@github-actions github-actions bot changed the title mbedtls_net_set_nonblock / mbedtls_net_set_block doesn't work mbedtls_net_set_nonblock / mbedtls_net_set_block doesn't work (IDFGH-2264) Nov 26, 2019
@szmodz
Copy link
Author

szmodz commented Nov 28, 2019

I've hacked around the C library problem, and it seems to work, but perhaps there are other issues with nonblocking sockets and that's why fcntl was disabled in the first place?

@szmodz
Copy link
Author

szmodz commented Dec 6, 2019

This code doesn't work at all with the 2019r2 toolchain:

https://github.com/espressif/esp-aws-iot/blob/0ba1fe942785b2efd553d73124afaef2f0327f41/port/network_mbedtls_wrapper.c#L208

It always fails with

ESP_LOGE(TAG, "failed! net_set_(non)block() returned -0x%x", -ret);

If you need test cases, here they are (Espressif's own code):
https://github.com/espressif/esp-aws-iot/tree/master/examples

The problem also applies to esp-tls:

int flags = fcntl(fd, F_GETFL, 0);

Basically anything that uses esp-tls in nonblocking mode is broken with the gcc 8.2 based toolchains. It just goes unnoticed because the call is not checked for errors.

@szmodz
Copy link
Author

szmodz commented Dec 11, 2019

Any ACK on this? I think this problem needs to be fixed, as it affects multiple esp-idf components, but I can keep posting bug reports... ;-)

One of the test cases for esp-idf should include nonblocking sockets. Apparently there's no such test.

This only relates to the gcc 8 based toolchains (including 2019r2).

@szmodz
Copy link
Author

szmodz commented Dec 11, 2019

This is why it works with gcc 5:

int __attribute__((weak)) fcntl(int fd, int cmd, ...)

(attribute weak)

48d9d50

#1070 (should be reopened)

@mahavirj
Copy link
Member

@szmodz

Any ACK on this? I think this problem needs to be fixed, as it affects multiple esp-idf components, but I can keep posting bug reports... ;-)

Thanks for reporting this issue. Fix has been merged for this internally, once ESP-IDF codebase sync with github, this issue will be marked as closed.

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