Skip to content

esp_websocket_client: Close connection when wtite timeout which is unexpected (IDFGH-16792) #942

@TempoTian

Description

@TempoTian

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

See following code. when write to socket, there is no error and only timeout when polling for write.
If user set timeout to be small value like 50ms, it will treat the normal timeout as error and close socket. Which cause websocket can not used any more.
I think the judge need update to wlen < 0 || (wlen == 0 && need_write != 0 && (timeout == portMAX_DELAY || errno))

        memcpy(client->tx_buffer, data + widx, need_write);
        // send with ws specific way and specific opcode
        wlen = esp_transport_ws_send_raw(client->transport, opcode, (char *)client->tx_buffer, need_write,
                                         (timeout == portMAX_DELAY) ? -1 : timeout * portTICK_PERIOD_MS);
        if (wlen < 0 || (wlen == 0 && need_write != 0)) {
            ret = wlen;
            esp_websocket_free_buf(client, true);
            esp_tls_error_handle_t error_handle = esp_transport_get_error_handle(client->transport);
            if (error_handle) {
                esp_websocket_client_error(client, "esp_transport_write() returned %d, transport_error=%s, tls_error_code=%i, tls_flags=%i, errno=%d",
                                           ret, esp_err_to_name(error_handle->last_error), error_handle->esp_tls_error_code,
                                           error_handle->esp_tls_flags, errno);
            } else {
                esp_websocket_client_error(client, "esp_transport_write() returned %d, errno=%d", ret, errno);
            }
            esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
            goto unlock_and_return;
        }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions