Fix client process for large packets #221
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue 1
When a large packet is received (greater than 1042), it is broken into separate parts. The calculation for
decrypted_size
had the incorrect value of18
instead of16
, sodecrypted size
was being calculated as1022
. Whenclient_decrypt
was called,decrypted_size
of1022
was less than the calculatedrequired_decrypted_size
of1024
causing it to fail withr = -2
.The error logs showed:
It then read the remaining part of the data, but was unable to decrypt it (perhaps because the first part wasn't decrypted?)
Adjusting the number from
18
to16
resolved the issue.Issue 2
I noticed that
homekit_client_process
was exiting before the full message was completed.The JSON is incomplete, and the HTTP parser has not indicated that the response was completed. Under low loads, the function would execute again, read the remaining part of the JSON, and successfully finish the message. However, under heavy client loads, it was possible for another client to connect and be processed, with the function trying to merge Client 1 and Client 4 data.
It appears that in the
while
check,data_available
is always0
as the buffer equals the block size. I believe this loop should only exit once the HTTP parser has indicated the message is indeed complete.The logs now look correct.