Skip to content

HTTP client seems to get stuck somewhere when error from transport layer is logged #632

@SeaRoll

Description

@SeaRoll

Bug description

We use the http client and whenever a connection is slow/lost for a short while, the error in the log says:

E (378225) transport_base: esp_tls_conn_read error, errno=No more processes
W (378225) HTTP_CLIENT: esp_transport_read returned:0 and errno:11

The current code looks like such:

fn get_cloud_device_data(
        &self,
    ) -> Result<CloudDeviceDataResponse> {
        let connection = EspHttpConnection::new(&Configuration {
            use_global_ca_store: true,
            crt_bundle_attach: Some(esp_idf_svc::sys::esp_crt_bundle_attach),
            timeout: Some(core::time::Duration::from_secs(30)),
            ..Default::default()
        })?;

        let mut client = Client::wrap(connection);

        let headers = [
            ("accept", "application/json"),
            ("cache-control", "no-cache"),
            ("content-type", "application/json"),
            ("content-length", &buf.len().to_string()),
        ];

        let mut request = client.request(Method::Post, DEVICE_DATA_ENDPOINT, &headers)?;
        request.write(&buf)?;

        log::info!("Submitting request");
        let response = request.submit()?;
        let status = response.status();

        log::info!("Received code: {}\n", status);

        match status {
            200 => {
                // Error seems to happen here somewhere
                let mut buf = [0_u8; 1024];
                let mut result = Vec::new();
                let mut reader = response;
                while let Ok(size) = Read::read(&mut reader, &mut buf) {
                    if size == 0 {
                        break;
                    }
                    result.extend_from_slice(&buf[..size]);
                }

                let result = serde_json::from_slice(&result)?;
                Ok(result)
            }
            _ => Err(anyhow::anyhow!("Unexpected response code: {}", status)),
        }
    }
  • Would you like to work on a fix? [y/n] (not yet, need to investigate why)

To Reproduce

  1. Have a bad internet connection (but still connected)
  2. Call any HTTP endpoint (that has lots of buffered data 400KB+)
  3. If the internet connection is bad enough, it gets stuck

Expected behavior

Some kind of error, but I am not sure if this is just me being bad at coding 🤔

Environment

  • Latest release
  • ESP32 v5.3.2
  • esp32s3
  • MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions