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

esp_websocket_client_send_with_opcode returns ESP_FAIL even if send is successful (IDFGH-11290) #392

Closed
3 tasks done
sjames opened this issue Oct 23, 2023 · 0 comments
Closed
3 tasks done
Assignees

Comments

@sjames
Copy link
Contributor

sjames commented Oct 23, 2023

Answers checklist.

  • I have read the documentation for esp-protocols components and the issue is not addressed there.
  • I have updated my esp-protocols branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

esp_websocket_client_send_with_opcode in https://github.com/espressif/esp-protocols/blob/3e8de3af3a8bda2c1b0b1eb3e20c277fe123c40a/components/esp_websocket_client/esp_websocket_client.c#L1201C5-L1201C42 always returns ESP_FAIL

This is a bug in the code. After all the operations are successful, the execution flows into the unlock_and_return label which incorrectly returns ESP_FAIL.

The fix is simple, here it is

int esp_websocket_client_send_with_opcode(esp_websocket_client_handle_t client, ws_transport_opcodes_t opcode, const uint8_t *data, int len, TickType_t timeout)
{
    int error = ESP_OK;
    if (client == NULL || len < 0 || (data == NULL && len > 0)) {
        ESP_LOGE(TAG, "Invalid arguments");
        return ESP_FAIL;
    }

    if (xSemaphoreTakeRecursive(client->lock, timeout) != pdPASS) {
        ESP_LOGE(TAG, "Could not lock ws-client within %" PRIu32 " timeout", timeout);
        return ESP_FAIL;
    }

    if (!esp_websocket_client_is_connected(client)) {
        ESP_LOGE(TAG, "Websocket client is not connected");
        error = ESP_FAIL;
        goto unlock_and_return;
    }

    if (client->transport == NULL) {
        ESP_LOGE(TAG, "Invalid transport");
        error = ESP_FAIL;
        goto unlock_and_return;
    }
    if (esp_websocket_new_buf(client, true) != ESP_OK) {
        ESP_LOGE(TAG, "Failed to setup tx buffer");
        error = ESP_FAIL;
        goto unlock_and_return;
    }
    if (esp_websocket_client_send_with_exact_opcode(client, opcode | WS_TRANSPORT_OPCODES_FIN, data, len, timeout) != true) {
        ESP_LOGE(TAG, "Failed to send the buffer");
        error = ESP_FAIL;
        goto unlock_and_return;
    }
unlock_and_return:
    xSemaphoreGiveRecursive(client->lock);
    return error;
}
@github-actions github-actions bot changed the title esp_websocket_client_send_with_opcode returns ESP_FAIL even if send is successful esp_websocket_client_send_with_opcode returns ESP_FAIL even if send is successful (IDFGH-11290) Oct 23, 2023
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

3 participants