Skip to content

Conversation

cjihrig
Copy link
Collaborator

@cjihrig cjihrig commented Jan 22, 2020

This depends on #90 (the first commit in this PR).

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: #88

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: #88
@cjihrig cjihrig merged commit eea4508 into master Jan 22, 2020
@cjihrig cjihrig deleted the close-race branch January 22, 2020 15:04
This was referenced Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in uvwasi_fd_close()

2 participants