[GIT PULL] Fix a memory leak bug in AsyncProgressWorkerBase#1264
Closed
ammarfaizi2 wants to merge 1 commit intonodejs:mainfrom
Closed
[GIT PULL] Fix a memory leak bug in AsyncProgressWorkerBase#1264ammarfaizi2 wants to merge 1 commit intonodejs:mainfrom
AsyncProgressWorkerBase#1264ammarfaizi2 wants to merge 1 commit intonodejs:mainfrom
Conversation
In `AsyncProgressWorkerBase<DataType>::NonBlockingCall` if the call to `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`, the ThreadSafeData object is not deleted by `OnAsyncWorkProgress()`, resulting a memory leak bug. Report from ASAN (Address Sanitizer): ``` Direct leak of 2706523824 byte(s) in 169157739 object(s) allocated: # 0 0x7fc83c2dd76d in operator new(unsigned long) # 1 0x7fc83b639fc2 in Napi::AsyncProgressWorkerBase<void>::NonBlockingCall(void*) # 2 0x7fc83b639fc2 in Napi::AsyncProgressWorker<unsigned char>::SendProgress_() # 3 0x7fc83b635cd0 in Napi::AsyncProgressWorker<unsigned char>::ExecutionProgress::Send() # 4 0x7fc83b635cd0 in WaitCQEWorker::Execute() # 5 0x7fc83b636545 in Napi::AsyncProgressWorker<unsigned char>::Execute() # 6 0xb8df59 in node::ThreadPoolWork::ScheduleWork()::'lambda'(uv_work_s*)::_FUN(uv_work_s*) # 7 0x1768fb3 in worker /home/iojs/build/ws/out/../deps/uv/src/threadpool.c:122:5 # 8 0x7fc83ba94b42 in start_thread nptl/./nptl/pthread_create.c:442:8 ``` Fix this by deleting the tsd variable if `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`. Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
KevinEady
approved these changes
Jan 5, 2023
Contributor
KevinEady
left a comment
There was a problem hiding this comment.
LGTM.
The ThreadSafeData was only deleted inside the OnAsyncWorkProgress callback, and of course if this call fails to schedule, it would never be deleted.
legendecas
approved these changes
Jan 6, 2023
mhdawson
pushed a commit
that referenced
this pull request
Jan 9, 2023
In `AsyncProgressWorkerBase<DataType>::NonBlockingCall` if the call to `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`, the ThreadSafeData object is not deleted by `OnAsyncWorkProgress()`, resulting a memory leak bug. Report from ASAN (Address Sanitizer): ``` Direct leak of 2706523824 byte(s) in 169157739 object(s) allocated: # 0 0x7fc83c2dd76d in operator new(unsigned long) # 1 0x7fc83b639fc2 in Napi::AsyncProgressWorkerBase<void>::NonBlockingCall(void*) # 2 0x7fc83b639fc2 in Napi::AsyncProgressWorker<unsigned char>::SendProgress_() # 3 0x7fc83b635cd0 in Napi::AsyncProgressWorker<unsigned char>::ExecutionProgress::Send() # 4 0x7fc83b635cd0 in WaitCQEWorker::Execute() # 5 0x7fc83b636545 in Napi::AsyncProgressWorker<unsigned char>::Execute() # 6 0xb8df59 in node::ThreadPoolWork::ScheduleWork()::'lambda'(uv_work_s*)::_FUN(uv_work_s*) # 7 0x1768fb3 in worker /home/iojs/build/ws/out/../deps/uv/src/threadpool.c:122:5 # 8 0x7fc83ba94b42 in start_thread nptl/./nptl/pthread_create.c:442:8 ``` Fix this by deleting the tsd variable if `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`. Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> PR-URL: #1264 Reviewed-By: Michael Dawson <midawson@redhat.com Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
Member
|
Landed in 01c6169 |
johnfrench3
pushed a commit
to johnfrench3/node-addon-api-git
that referenced
this pull request
Aug 11, 2023
In `AsyncProgressWorkerBase<DataType>::NonBlockingCall` if the call to `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`, the ThreadSafeData object is not deleted by `OnAsyncWorkProgress()`, resulting a memory leak bug. Report from ASAN (Address Sanitizer): ``` Direct leak of 2706523824 byte(s) in 169157739 object(s) allocated: # 0 0x7fc83c2dd76d in operator new(unsigned long) # 1 0x7fc83b639fc2 in Napi::AsyncProgressWorkerBase<void>::NonBlockingCall(void*) # 2 0x7fc83b639fc2 in Napi::AsyncProgressWorker<unsigned char>::SendProgress_() # 3 0x7fc83b635cd0 in Napi::AsyncProgressWorker<unsigned char>::ExecutionProgress::Send() # 4 0x7fc83b635cd0 in WaitCQEWorker::Execute() # 5 0x7fc83b636545 in Napi::AsyncProgressWorker<unsigned char>::Execute() # 6 0xb8df59 in node::ThreadPoolWork::ScheduleWork()::'lambda'(uv_work_s*)::_FUN(uv_work_s*) # 7 0x1768fb3 in worker /home/iojs/build/ws/out/../deps/uv/src/threadpool.c:122:5 # 8 0x7fc83ba94b42 in start_thread nptl/./nptl/pthread_create.c:442:8 ``` Fix this by deleting the tsd variable if `_tsfn.NonBlockingCall()` doesn't return a `napi_ok`. Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> PR-URL: nodejs/node-addon-api#1264 Reviewed-By: Michael Dawson <midawson@redhat.com Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi,
We found a serious memory leak issue in the async worker. ASAN reported
2706523824 bytes (~2.5 GB) direct leak in our application that uses
node-addon-api.
Short technical explanation:
In
AsyncProgressWorkerBase<DataType>::NonBlockingCallif the call to_tsfn.NonBlockingCall()doesn't return anapi_ok, theThreadSafeDataobject is not deleted by
OnAsyncWorkProgress(), resulting a memoryleak bug.
Report from ASAN (Address Sanitizer):
Fix this by deleting the tsd variable if
_tsfn.NonBlockingCall()doesn't return a
napi_ok.Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Please pull!