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

Incorrect restoring of responces from chunked cache entries #803

Closed
vankoven opened this issue Aug 17, 2017 · 3 comments
Closed

Incorrect restoring of responces from chunked cache entries #803

vankoven opened this issue Aug 17, 2017 · 3 comments
Assignees
Labels
bug cache crucial TDB Tempesta DB module and related issues
Milestone

Comments

@vankoven
Copy link
Contributor

Applicable to saving and restoring responses from chunked cache entry. There is a situation when TfwCStr header can't be fit into the rest of current data chunk (TdbVRec). In this case TfwCStr will be saved into the next record. This condition is handled in tfw_cache_copy_hdr():

*p = tdb_entry_get_room(node_db(), trec, *p, n, *tot_len);

The tfw_cache_copy_hdr() has also an optimization in order not to split short TfwCStr:

/* Don't split short strings. */
if (likely(!TFW_STR_DUP(src))
&& sizeof(TfwCStr) + src->len <= L1_CACHE_BYTES)
n += src->len;

But there is a couple of issues, when restoring responses from a cache entry. First of all optimization above is ignored. So if a response is written to cache with at least one such optimisation we can expect crash or serving corrupted response.

Secondly, crash will happen in tfw_cache_build_resp_hdr() if TfwCstr of the next header couldn't fit the rest of the current chunk and was placed into the next one:

tempesta/tempesta_fw/cache.c

Lines 1019 to 1020 in 65d9723

*p += TFW_CSTR_HDRLEN;
BUG_ON(*p > (*trec)->data + (*trec)->len);

To fix both issues we need to add a function to adjust current pointer in the current data chunk before reading TfwCStr similarly to tdb_entry_get_room() which is used before writing. And use the function any time we are reading a TfwCStr. To make function aware of optimization above, we need to write a padding TfwCStr header with flag SKIP_REC_TAIL set every time when the optimization is used. The flag will help us understand that the rest of data chunk doesn't contain any data and must be skipped. tdb_entry_get_room() must write this padding TfwCStr header.

@vankoven vankoven added the bug label Aug 17, 2017
@vankoven vankoven added this to the 0.5.0 Web Server milestone Aug 17, 2017
@vankoven vankoven self-assigned this Aug 17, 2017
@vankoven
Copy link
Contributor Author

Note the #804 issue describing unit tests for this issue.

@krizhanovsky
Copy link
Contributor

krizhanovsky commented Aug 17, 2017

It's better to fix this after #515 which will affect caching a lot.

@krizhanovsky krizhanovsky modified the milestones: 1.0 Web Operating System, 0.9 Web server Jan 14, 2018
@krizhanovsky krizhanovsky modified the milestones: 1.3 Web server, 1.2 TDB v0.2 Aug 8, 2018
@krizhanovsky krizhanovsky modified the milestones: 1.2 TDB v0.2, 1.0 Beta Nov 19, 2018
@krizhanovsky krizhanovsky changed the title [Cache] Incorrect restoring of responces from chunked cache entries Incorrect restoring of responces from chunked cache entries Mar 16, 2020
@krizhanovsky krizhanovsky added the TDB Tempesta DB module and related issues label Apr 27, 2020
@krizhanovsky krizhanovsky modified the milestones: 0.10 - TDBv0.2, 0.8 - HTTP normalization May 18, 2022
@krizhanovsky krizhanovsky self-assigned this Jan 10, 2023
@krizhanovsky krizhanovsky modified the milestones: 0.7 - Beta, 1.0 - GA Apr 19, 2023
@krizhanovsky krizhanovsky assigned const-t and unassigned krizhanovsky May 18, 2023
@const-t
Copy link
Contributor

const-t commented Jun 7, 2023

Fixed by #1831

@const-t const-t closed this as completed Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cache crucial TDB Tempesta DB module and related issues
Projects
None yet
Development

No branches or pull requests

3 participants