Closes https://github.com/espressif/esp-idf/issues/3011 (cherry picked from commit ce4944edf01b2a4c997eafe36b66d71f98f2fe29)