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

[BUG] Use local GC ctx in periodic callback #2962

Merged
merged 13 commits into from Aug 5, 2022
Merged

[BUG] Use local GC ctx in periodic callback #2962

merged 13 commits into from Aug 5, 2022

Conversation

ashtul
Copy link
Contributor

@ashtul ashtul commented Aug 4, 2022

Using RSDummeyCtx with AutoMemory caused memory corruption as Redis maintains a list of freed pointers.
When RM_RetainString is called on a pointer in the auto memory pointer list, Redis does not increase the ref count, which causes double free.

MOD-3951
Fixes #2766

rafie
rafie previously approved these changes Aug 4, 2022
@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2022

This pull request introduces 1 alert when merging f711348 into d5a17d3 - view on LGTM.com

new alerts:

  • 1 for Dead code due to goto or break statement

oshadmi
oshadmi previously approved these changes Aug 4, 2022
Copy link
Collaborator

@oshadmi oshadmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@ashtul ashtul dismissed stale reviews from oshadmi and rafie via 7c17188 August 4, 2022 11:56
@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2022

This pull request introduces 1 alert when merging 7c17188 into d5a17d3 - view on LGTM.com

new alerts:

  • 1 for Dead code due to goto or break statement

src/spec.c Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 4, 2022

Codecov Report

Merging #2962 (8d3c6e1) into master (a1d597f) will increase coverage by 0.01%.
The diff coverage is 82.92%.

❗ Current head 8d3c6e1 differs from pull request most recent head c9b6f97. Consider uploading reports for the commit c9b6f97 to get more accurate results

@@            Coverage Diff             @@
##           master    #2962      +/-   ##
==========================================
+ Coverage   81.92%   81.94%   +0.01%     
==========================================
  Files         180      180              
  Lines       29264    29452     +188     
==========================================
+ Hits        23974    24133     +159     
- Misses       5290     5319      +29     
Impacted Files Coverage Δ
src/aggregate/aggregate_exec.c 95.31% <ø> (ø)
src/config.h 100.00% <ø> (ø)
src/doc_types.h 100.00% <ø> (ø)
src/query_error.h 100.00% <ø> (ø)
src/util/dict.c 52.73% <37.50%> (-0.35%) ⬇️
src/gc.c 76.15% <55.55%> (-1.72%) ⬇️
src/document.c 73.78% <73.21%> (-0.85%) ⬇️
src/json.c 88.03% <82.50%> (-4.92%) ⬇️
src/query.c 90.35% <86.66%> (-0.13%) ⬇️
src/aggregate/aggregate_request.c 96.16% <100.00%> (+<0.01%) ⬆️
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@MeirShpilraien MeirShpilraien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, why comment a test?

@oshadmi oshadmi requested review from rafie and MeirShpilraien and removed request for oshadmi August 5, 2022 06:48
src/gc.c Outdated
RedisModuleCtx* ctx;
switch (RSGlobalConfig.gcPolicy) {
case GCPolicy_Fork:
ctx = ((ForkGC *)(gc->gcCtx))->ctx;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is no harm in creating ThreadSafeCtx anyway each time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with RedisModule_GetThreadSafeContext and freed.
Let's push this.

@@ -79,7 +79,7 @@ static void threadCallback(void* data) {
GCTask* task= data;
GCContext* gc = task->gc;
RedisModuleBlockedClient* bc = task->bClient;
RedisModuleCtx* ctx = RSDummyContext;
RedisModuleCtx* ctx = RedisModule_GetThreadSafeContext(NULL);

if (gc->stopped) {
// if the client is blocked, lets release it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Free ctx here

Copy link
Collaborator

@MeirShpilraien MeirShpilraien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment, other then this looks good

@ashtul ashtul merged commit 3f7c8db into master Aug 5, 2022
@ashtul ashtul deleted the ariel_use-gc-ctx branch August 5, 2022 09:34
rafie pushed a commit that referenced this pull request Aug 5, 2022
* Use local GC ctx and add logs

* get the right ctx

* per review

* add test

* Skip GC on cluster and temporarily comment out part of testMultiTextNested

* streamline code

* test fixed in #2967

* fix leak

Co-authored-by: oshadmi <omer.shadmi@redislabs.com>
Co-authored-by: Omer Shadmi <76992134+oshadmi@users.noreply.github.com>
(cherry picked from commit 3f7c8db)
ashtul pushed a commit that referenced this pull request Aug 5, 2022
* Use local GC ctx and add logs

* get the right ctx

* per review

* add test

* Skip GC on cluster and temporarily comment out part of testMultiTextNested

* streamline code

* test fixed in #2967

* fix leak

Co-authored-by: oshadmi <omer.shadmi@redislabs.com>
Co-authored-by: Omer Shadmi <76992134+oshadmi@users.noreply.github.com>
(cherry picked from commit 3f7c8db)
ashtul pushed a commit that referenced this pull request Aug 7, 2022
* Use local GC ctx and add logs

* get the right ctx

* per review

* add test

* Skip GC on cluster and temporarily comment out part of testMultiTextNested

* streamline code

* test fixed in #2967

* fix leak

Co-authored-by: oshadmi <omer.shadmi@redislabs.com>
Co-authored-by: Omer Shadmi <76992134+oshadmi@users.noreply.github.com>
(cherry picked from commit 3f7c8db)
oshadmi added a commit that referenced this pull request Aug 8, 2022
* Use local GC ctx and add logs

* get the right ctx

* per review

* add test

* Skip GC on cluster and temporarily comment out part of testMultiTextNested

* streamline code

* test fixed in #2967

* fix leak

Co-authored-by: oshadmi <omer.shadmi@redislabs.com>
Co-authored-by: Omer Shadmi <76992134+oshadmi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CRASH] while scanning documents with Indexes_FindMatchingSchemaRules
4 participants