Page MenuHomePhabricator

Small CHUNKSIZE in connector.c can cause output hangs
Open, Needs TriagePublic


In the Multipass project [1], we use an ssh client implementation similar to the ssh_client example where connectors are used. We are running into an issue where if a ssh_channel_request_exec() is called via the client, that the client can "hang" if it is receiving large amounts of data.

I narrowed this issue down to ssh_connector_fd_out_cb() and the ssh_channel_read_nonblocking() call. Whenever there is more data to be read than CHUNKSIZE (which is 4096 bytes), then there is no way for the code to go back and read more data on the particular event. I found that increasing CHUNKSIZE to 65536 bytes keeps the issue from occurring. This allows the buffer to be larger than the TCP max buffer size and so all data in the packet will be accounted for.

A proper fix would most likely entail detecting if there is more data associated with the particular event and reading again from the socket. The tricky part will be determining if it is indeed from the same event or if it's from a different event.