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

Make symbolize.cc thread safe even on shared fds #388

Merged
merged 1 commit into from
Nov 14, 2018
Merged

Conversation

tzik
Copy link
Contributor

@tzik tzik commented Nov 13, 2018

ReadFromOffset in symbolize.cc used to call lseek() + read() to read
data from fd. However, the fd may be reused for multiple symbolize
requests from multiple threads, and causes a race around the fd read
offset.

This updates it to use pread() to resolve the race.

ReadFromOffset in symbolize.cc used to call lseek() + read() to read
data from fd. However, the fd may be reused for multiple symbolize
requests from multiple threads, and causes a race around the fd read
offset.

This updates it to use pread() to resolve the race.
@tzik
Copy link
Contributor Author

tzik commented Nov 13, 2018

JFYI @hajimehoshi

SAFE_ASSERT(fd >= 0);
SAFE_ASSERT(count <= std::numeric_limits<ssize_t>::max());
char *buf0 = reinterpret_cast<char *>(buf);
ssize_t num_bytes = 0;
while (num_bytes < count) {
ssize_t len;
NO_INTR(len = read(fd, buf0 + num_bytes, count - num_bytes));
NO_INTR(len = pread(fd, buf0 + num_bytes, count - num_bytes,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it available on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, but IIUC, this is not used on Windows as we have defined(OS_WINDOWS) || defined(OS_CYGWIN) branch below.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ok.

@ukai ukai merged commit c44e3bb into google:master Nov 14, 2018
durswd pushed a commit to durswd/glog that referenced this pull request Sep 2, 2019
Make symbolize.cc thread safe even on shared fds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants