Skip to content

Conversation

@addaleax
Copy link
Member

  • Prefer RAII-style management over manual resource management.
  • Prefer env->SetImmediate() over a separate uv_async_t.
  • Perform ares_destroy() before possibly tearing down c-ares state.
  • Verify that the number of active queries is non-negative.
  • Let pending callbacks know when their underlying QueryWrap object
    has been destroyed.

The last item has been a real bug, in that when Workers shut down
during currently running DNS queries, they may run into use-after-free
situations because:

  1. Shutting the Worker down leads to the cleanup code deleting
    the QueryWrap objects first; then
  2. deleting the ChannelWrap object (as it has been created before
    the QueryWraps), whose destructor runs ares_destroy(), which
    in turn invokes all pending query callbacks with ARES_ECANCELLED,
  3. which lead to use-after-free, as the callback tried to access the
    deleted QueryWrap object.

The added test verifies that this is no longer an issue.

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

- Prefer RAII-style management over manual resource management. - Prefer `env->SetImmediate()` over a separate `uv_async_t`. - Perform `ares_destroy()` before possibly tearing down c-ares state. - Verify that the number of active queries is non-negative. - Let pending callbacks know when their underlying `QueryWrap` object has been destroyed. The last item has been a real bug, in that when Workers shut down during currently running DNS queries, they may run into use-after-free situations because: 1. Shutting the `Worker` down leads to the cleanup code deleting the `QueryWrap` objects first; then 2. deleting the `ChannelWrap` object (as it has been created before the `QueryWrap`s), whose destructor runs `ares_destroy()`, which in turn invokes all pending query callbacks with `ARES_ECANCELLED`, 3. which lead to use-after-free, as the callback tried to access the deleted `QueryWrap` object. The added test verifies that this is no longer an issue.
@addaleaxaddaleax added the dns Issues and PRs related to the dns subsystem. label Feb 21, 2019
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. labels Feb 21, 2019
@addaleaxaddaleax added worker Issues and PRs related to Worker support. and removed cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. labels Feb 21, 2019
@addaleax
Copy link
MemberAuthor

Maybe one of @XadillaX@gireeshpunathil@joyeecheung@cjihrig could review this?

@addaleax
Copy link
MemberAuthor

@addaleaxaddaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 1, 2019
@addaleax
Copy link
MemberAuthor

@addaleax
Copy link
MemberAuthor

Landed in 018e95a

@addaleaxaddaleax closed this Mar 1, 2019
@addaleaxaddaleax deleted the cares-terminate branch March 1, 2019 21:20
addaleax added a commit that referenced this pull request Mar 1, 2019
- Prefer RAII-style management over manual resource management. - Prefer `env->SetImmediate()` over a separate `uv_async_t`. - Perform `ares_destroy()` before possibly tearing down c-ares state. - Verify that the number of active queries is non-negative. - Let pending callbacks know when their underlying `QueryWrap` object has been destroyed. The last item has been a real bug, in that when Workers shut down during currently running DNS queries, they may run into use-after-free situations because: 1. Shutting the `Worker` down leads to the cleanup code deleting the `QueryWrap` objects first; then 2. deleting the `ChannelWrap` object (as it has been created before the `QueryWrap`s), whose destructor runs `ares_destroy()`, which in turn invokes all pending query callbacks with `ARES_ECANCELLED`, 3. which lead to use-after-free, as the callback tried to access the deleted `QueryWrap` object. The added test verifies that this is no longer an issue. PR-URL: #26253 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
addaleax added a commit that referenced this pull request Mar 1, 2019
- Prefer RAII-style management over manual resource management. - Prefer `env->SetImmediate()` over a separate `uv_async_t`. - Perform `ares_destroy()` before possibly tearing down c-ares state. - Verify that the number of active queries is non-negative. - Let pending callbacks know when their underlying `QueryWrap` object has been destroyed. The last item has been a real bug, in that when Workers shut down during currently running DNS queries, they may run into use-after-free situations because: 1. Shutting the `Worker` down leads to the cleanup code deleting the `QueryWrap` objects first; then 2. deleting the `ChannelWrap` object (as it has been created before the `QueryWrap`s), whose destructor runs `ares_destroy()`, which in turn invokes all pending query callbacks with `ARES_ECANCELLED`, 3. which lead to use-after-free, as the callback tried to access the deleted `QueryWrap` object. The added test verifies that this is no longer an issue. PR-URL: #26253 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
@BridgeARBridgeAR mentioned this pull request Mar 4, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs 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++.dnsIssues and PRs related to the dns subsystem.workerIssues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@addaleax@nodejs-github-bot@jasnell@cjihrig