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

deps: update to uvwasi 0.0.5 #31432

Closed
wants to merge 5 commits into from
Closed

deps: update to uvwasi 0.0.5 #31432

wants to merge 5 commits into from

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jan 20, 2020

This update improves file descriptor renumbering, and as a result fixes uvwasi_fd_renumber() (which was broken on FreeBSD). Missing uvwasi_fd_renumber() test coverage is also added via an freopen() test.

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

@nodejs-github-bot nodejs-github-bot added the wasi Issues and PRs related to the WebAssembly System Interface. label Jan 20, 2020
uv_fs_req_cleanup(&req);
if (r != 0) {
uv_mutex_unlock(&dst_entry->mutex);
uv_mutex_unlock(&src_entry->mutex);
Copy link
Member

Choose a reason for hiding this comment

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

These unlocks and the ones at lines 383-384 look like a potential deadlock. You should normally release mutexes in reverse order of acquiring them.

Even when there's no deadlock it's probably still bad for performance because the acquirer can get rescheduled twice in case of contention.

/* Move the source entry to the destination slot in the table. */
table->fds[dst] = table->fds[src];
table->fds[dst]->id = dst;
uv_mutex_unlock(&table->fds[dst]->mutex);
Copy link
Member

Choose a reason for hiding this comment

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

I'm also not 100% sure it's safe for this mutex's critical section and &table->rwlock to overlap (but it might be - I just can't tell from the diff. :-))

This version improves file descriptor renumbering, and as a result
fixes uvwasi_fd_renumber().
Original commit message:

    unlock all fd mutexes in reverse order

    Some functions acquire mutexes for multiple file descriptors.
    This commit ensures that the mutexes are released in the
    reverse order that they are aquired.
Original commit message:
    prevent locking fd table while holding a mutex

    uvwasi_path_rename(), uvwasi_path_link(),
    uvwasi_path_open(), and uvwasi_fd_renumber() operate
    on multiple file descriptors. uvwasi_fd_renumber() has
    been updated prior to this commit, and is not relevant
    here. The other three functions would perform the
    following locking operations:

    - lock the file table
    - acquire a file descriptor mutex
    - unlock the file table
    - unlock the file table again
    - acquire another file descriptor mutex
    - unlock the file table
    - unlock the two mutexes

    Attempting to acquire the second mutex introduced
    the possibility of deadlock because another thread
    could attempt to acquire the first mutex while
    holding the file table lock.

    This commit ensures that multiple mutexes are either:
    - acquired in a single lock of the file table
    - or, only acquired after releasing previously held mutexes

    Fixes: nodejs/uvwasi#89
Original commit message:

    prevent race conditions with uvwasi_fd_close()

    uvwasi_fd_close() performed the following operations:

    - lock the file descriptor mutex
    - close the file
    - release the file descriptor mutex
    - call the file table's remove() function

    Once the fd's mutex is released, another thread could
    acquire it before the fd is removed from the file
    table. If this happens, remove() could destroy a held
    mutex.

    This commit updates uvwasi_fd_close() to perform the
    entire sequence while holding the file table's lock,
    preventing new acquisitions of the fd's mutex.

    Fixes: nodejs/uvwasi#88
This test provides missing coverage for __wasi_fd_renumber().
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@cjihrig cjihrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 23, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jan 23, 2020

@Trott
Copy link
Member

Trott commented Jan 23, 2020

Landed in c692568...96058f3

@Trott Trott closed this Jan 23, 2020
Trott pushed a commit to Trott/io.js that referenced this pull request Jan 23, 2020
This version improves file descriptor renumbering, and as a result
fixes uvwasi_fd_renumber().

PR-URL: nodejs#31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Trott pushed a commit to Trott/io.js that referenced this pull request Jan 23, 2020
Original commit message:

    unlock all fd mutexes in reverse order

    Some functions acquire mutexes for multiple file descriptors.
    This commit ensures that the mutexes are released in the
    reverse order that they are aquired.

PR-URL: nodejs#31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Trott pushed a commit to Trott/io.js that referenced this pull request Jan 23, 2020
Original commit message:
    prevent locking fd table while holding a mutex

    uvwasi_path_rename(), uvwasi_path_link(),
    uvwasi_path_open(), and uvwasi_fd_renumber() operate
    on multiple file descriptors. uvwasi_fd_renumber() has
    been updated prior to this commit, and is not relevant
    here. The other three functions would perform the
    following locking operations:

    - lock the file table
    - acquire a file descriptor mutex
    - unlock the file table
    - unlock the file table again
    - acquire another file descriptor mutex
    - unlock the file table
    - unlock the two mutexes

    Attempting to acquire the second mutex introduced
    the possibility of deadlock because another thread
    could attempt to acquire the first mutex while
    holding the file table lock.

    This commit ensures that multiple mutexes are either:
    - acquired in a single lock of the file table
    - or, only acquired after releasing previously held mutexes

    Fixes: nodejs/uvwasi#89

PR-URL: nodejs#31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Trott pushed a commit that referenced this pull request Jan 23, 2020
Original commit message:

    prevent race conditions with uvwasi_fd_close()

    uvwasi_fd_close() performed the following operations:

    - lock the file descriptor mutex
    - close the file
    - release the file descriptor mutex
    - call the file table's remove() function

    Once the fd's mutex is released, another thread could
    acquire it before the fd is removed from the file
    table. If this happens, remove() could destroy a held
    mutex.

    This commit updates uvwasi_fd_close() to perform the
    entire sequence while holding the file table's lock,
    preventing new acquisitions of the fd's mutex.

    Fixes: nodejs/uvwasi#88

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Trott pushed a commit to Trott/io.js that referenced this pull request Jan 23, 2020
This test provides missing coverage for __wasi_fd_renumber().

PR-URL: nodejs#31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
@cjihrig cjihrig deleted the uvwasi branch January 23, 2020 14:49
codebytere pushed a commit that referenced this pull request Feb 17, 2020
This version improves file descriptor renumbering, and as a result
fixes uvwasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Feb 17, 2020
Original commit message:

    unlock all fd mutexes in reverse order

    Some functions acquire mutexes for multiple file descriptors.
    This commit ensures that the mutexes are released in the
    reverse order that they are aquired.

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Feb 17, 2020
Original commit message:
    prevent locking fd table while holding a mutex

    uvwasi_path_rename(), uvwasi_path_link(),
    uvwasi_path_open(), and uvwasi_fd_renumber() operate
    on multiple file descriptors. uvwasi_fd_renumber() has
    been updated prior to this commit, and is not relevant
    here. The other three functions would perform the
    following locking operations:

    - lock the file table
    - acquire a file descriptor mutex
    - unlock the file table
    - unlock the file table again
    - acquire another file descriptor mutex
    - unlock the file table
    - unlock the two mutexes

    Attempting to acquire the second mutex introduced
    the possibility of deadlock because another thread
    could attempt to acquire the first mutex while
    holding the file table lock.

    This commit ensures that multiple mutexes are either:
    - acquired in a single lock of the file table
    - or, only acquired after releasing previously held mutexes

    Fixes: nodejs/uvwasi#89

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Feb 17, 2020
Original commit message:

    prevent race conditions with uvwasi_fd_close()

    uvwasi_fd_close() performed the following operations:

    - lock the file descriptor mutex
    - close the file
    - release the file descriptor mutex
    - call the file table's remove() function

    Once the fd's mutex is released, another thread could
    acquire it before the fd is removed from the file
    table. If this happens, remove() could destroy a held
    mutex.

    This commit updates uvwasi_fd_close() to perform the
    entire sequence while holding the file table's lock,
    preventing new acquisitions of the fd's mutex.

    Fixes: nodejs/uvwasi#88

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Feb 17, 2020
This test provides missing coverage for __wasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
@codebytere codebytere mentioned this pull request Feb 17, 2020
codebytere pushed a commit that referenced this pull request Mar 15, 2020
This version improves file descriptor renumbering, and as a result
fixes uvwasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 15, 2020
Original commit message:

    unlock all fd mutexes in reverse order

    Some functions acquire mutexes for multiple file descriptors.
    This commit ensures that the mutexes are released in the
    reverse order that they are aquired.

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 15, 2020
Original commit message:
    prevent locking fd table while holding a mutex

    uvwasi_path_rename(), uvwasi_path_link(),
    uvwasi_path_open(), and uvwasi_fd_renumber() operate
    on multiple file descriptors. uvwasi_fd_renumber() has
    been updated prior to this commit, and is not relevant
    here. The other three functions would perform the
    following locking operations:

    - lock the file table
    - acquire a file descriptor mutex
    - unlock the file table
    - unlock the file table again
    - acquire another file descriptor mutex
    - unlock the file table
    - unlock the two mutexes

    Attempting to acquire the second mutex introduced
    the possibility of deadlock because another thread
    could attempt to acquire the first mutex while
    holding the file table lock.

    This commit ensures that multiple mutexes are either:
    - acquired in a single lock of the file table
    - or, only acquired after releasing previously held mutexes

    Fixes: nodejs/uvwasi#89

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 15, 2020
Original commit message:

    prevent race conditions with uvwasi_fd_close()

    uvwasi_fd_close() performed the following operations:

    - lock the file descriptor mutex
    - close the file
    - release the file descriptor mutex
    - call the file table's remove() function

    Once the fd's mutex is released, another thread could
    acquire it before the fd is removed from the file
    table. If this happens, remove() could destroy a held
    mutex.

    This commit updates uvwasi_fd_close() to perform the
    entire sequence while holding the file table's lock,
    preventing new acquisitions of the fd's mutex.

    Fixes: nodejs/uvwasi#88

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 15, 2020
This test provides missing coverage for __wasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 17, 2020
This version improves file descriptor renumbering, and as a result
fixes uvwasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 17, 2020
Original commit message:

    unlock all fd mutexes in reverse order

    Some functions acquire mutexes for multiple file descriptors.
    This commit ensures that the mutexes are released in the
    reverse order that they are aquired.

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 17, 2020
Original commit message:
    prevent locking fd table while holding a mutex

    uvwasi_path_rename(), uvwasi_path_link(),
    uvwasi_path_open(), and uvwasi_fd_renumber() operate
    on multiple file descriptors. uvwasi_fd_renumber() has
    been updated prior to this commit, and is not relevant
    here. The other three functions would perform the
    following locking operations:

    - lock the file table
    - acquire a file descriptor mutex
    - unlock the file table
    - unlock the file table again
    - acquire another file descriptor mutex
    - unlock the file table
    - unlock the two mutexes

    Attempting to acquire the second mutex introduced
    the possibility of deadlock because another thread
    could attempt to acquire the first mutex while
    holding the file table lock.

    This commit ensures that multiple mutexes are either:
    - acquired in a single lock of the file table
    - or, only acquired after releasing previously held mutexes

    Fixes: nodejs/uvwasi#89

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 17, 2020
Original commit message:

    prevent race conditions with uvwasi_fd_close()

    uvwasi_fd_close() performed the following operations:

    - lock the file descriptor mutex
    - close the file
    - release the file descriptor mutex
    - call the file table's remove() function

    Once the fd's mutex is released, another thread could
    acquire it before the fd is removed from the file
    table. If this happens, remove() could destroy a held
    mutex.

    This commit updates uvwasi_fd_close() to perform the
    entire sequence while holding the file table's lock,
    preventing new acquisitions of the fd's mutex.

    Fixes: nodejs/uvwasi#88

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
codebytere pushed a commit that referenced this pull request Mar 17, 2020
This test provides missing coverage for __wasi_fd_renumber().

PR-URL: #31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
@codebytere codebytere mentioned this pull request Mar 17, 2020
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. wasi Issues and PRs related to the WebAssembly System Interface.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants