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

src: shutdown libuv before exit() #35021

Merged
merged 1 commit into from
Sep 5, 2020
Merged

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Sep 2, 2020

This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
exit(), such as in the added test example here.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@addaleax addaleax added lib / src Issues and PRs related to general changes in the lib or src directory. lts-watch-v10.x labels Sep 2, 2020
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Sep 2, 2020
@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

We should fast track this. It also needs to be backported to 14.x and 12.x. haven't tried 10.x but likely there too.

@addaleax addaleax added the fast-track PRs that do not need to wait for 48 hours to land. label Sep 2, 2020
@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2020
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Sep 2, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2020
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2020
@nodejs-github-bot
Copy link
Collaborator

@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

I'll investigate shortly why it's failing on windows

@addaleax addaleax removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. fast-track PRs that do not need to wait for 48 hours to land. labels Sep 2, 2020
@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

Ok... well... the failure on windows is still a segfault in the openssl EVP_PKEY_keygen call so this doesn't appear that it is fixing that problem, unfortunately. The uv_library_shutdown() call is happening...

I instrumented with some printf statements... here's what I'm seeing:

ENTERED EVP_PKEY_keygen is printed from immediately inside EVP_PKEY_keygen() when it is called. If that function exits, there's supposed to be a corresponding EXITING EVP_PKEY_keygen statement.

The uv_library_shutdown statement is printed immediately before the added call to uv_library_shutdown() that this PR adds.

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
-1073741819

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
uv_library_shutdown
0

Now, that said, it does appear to segfault occasionally after EVP_PKEY_keygen exits ... (the 5 in the output below simply identifies which return statement inside EVP_PKEY_keygen ran

C:\Users\jasne\Projects\node>Release\node test\parallel\test-crypto-op-during-process-exit & echo %errorlevel%
ENTERED EVP_PKEY_keygen
EXITING EVP_PKEY_keygen 5
uv_library_shutdown
-1073741819

@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

Ok, there are two distinct failure patterns that I'm seeing here:

Segfault sometime after the uv_library_shutdown() call when EVP_PKEY_keygen() is running and...

Segfault sometime after the CryptoJob completes and is deconstructed, but always after the uv_library_shutdown() call.

@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

I'm attempting to do a debug build on windows now. It's going to take a while and I'm not sure if it's going to build successfully. The last time I tried a debug build on windows it failed....

@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

Ok. So, yeah, at least on Windows this PR is not fixing the problem. windbg is reporting Invalid access exception at...

image

@jasnell
Copy link
Member

jasnell commented Sep 2, 2020

Ok, libuv PR open here: libuv/libuv#2983

This PR should also land but the libuv fix will be necessary for the test case here to pass on windows. @addaleax, we can keep this PR open until we get the libuv fix, or, we can perhaps move the test into the known_issues set and get this landed now. Once the libuv fix lands here, we can move the test back into parallel. What do you think?

@addaleax
Copy link
Member Author

addaleax commented Sep 2, 2020

we can perhaps move the test into the known_issues set and get this landed now.

The problem with that is that it will not crash reliably anywhere, and currently only does so on Windows… we could just skip the test on Windows if you like, and undo that when the libuv fix lands? Does that sound okay? (If yes, please push to this branch directly, I’ll be away for ~24 hours :))

@jasnell
Copy link
Member

jasnell commented Sep 3, 2020

Yeah that sounds good. I'll push that in the morning

@addaleax addaleax added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Sep 3, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 3, 2020
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@juanarbol juanarbol left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Sep 5, 2020

Landed in e326c41

@Trott Trott merged commit e326c41 into nodejs:master Sep 5, 2020
This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
`exit()`, such as in the added test example here.

PR-URL: nodejs#35021
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
richardlau pushed a commit that referenced this pull request Sep 7, 2020
This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
`exit()`, such as in the added test example here.

PR-URL: #35021
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@richardlau richardlau mentioned this pull request Sep 7, 2020
4 tasks
richardlau pushed a commit that referenced this pull request Sep 7, 2020
This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
`exit()`, such as in the added test example here.

PR-URL: #35021
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
addaleax added a commit that referenced this pull request Sep 23, 2020
This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
`exit()`, such as in the added test example here.

PR-URL: #35021
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@codebytere codebytere mentioned this pull request Sep 28, 2020
@addaleax addaleax deleted the uv-shutdown branch October 14, 2020 12:45
joesepi pushed a commit to joesepi/node that referenced this pull request Jan 8, 2021
This ensures that no operations will be running on the libuv
threadpool, which is important because they may run into race
conditions with the global destructors being triggered from
`exit()`, such as in the added test example here.

PR-URL: nodejs#35021
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
bnoordhuis pushed a commit to jasnell/libuv that referenced this pull request Jan 23, 2021
vtjnash pushed a commit to libuv/libuv that referenced this pull request May 28, 2021
Fixes: #2980
Refs: nodejs/node#35021
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jameson Nash <[email protected]>
JeffroMF pushed a commit to JeffroMF/libuv that referenced this pull request May 16, 2022
Fixes: libuv#2980
Refs: nodejs/node#35021
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jameson Nash <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.