This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add missing EINTR handling
ClosedPublic

Authored by mgorny on Mar 20 2019, 11:25 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

mgorny created this revision.Mar 20 2019, 11:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2019, 11:25 AM

The "problem" I have with this is that (IIRC) retrying close(2) on EINTR is the *wrong* thing to do on linux (because the fd will be closed anyway, and so we may end up closing someone else's file the second time around). I'll try to dig up more info about that tomorrow.

The "problem" I have with this is that (IIRC) retrying close(2) on EINTR is the *wrong* thing to do on linux (because the fd will be closed anyway, and so we may end up closing someone else's file the second time around). I'll try to dig up more info about that tomorrow.

Just found http://alobbs.com/post/54503240599/close-and-eintr and indeed you're right. While I find that behavior really silly and would consider it a bug, I see that POSIX considers it 'undefined' whether the file is closed or not. I guess I'll have to be more careful when deciding which syscalls to wrap.

Hmm, I also see that LLVM has signal-safe Process::SafelyCloseFileDescriptor(). Should I use that, or just ignore potential issues with close()?

mgorny updated this revision to Diff 191553.Mar 20 2019, 12:05 PM

Got rid of close() and fclose() wrapping, for now.

LGTM as long as the test suite is happy

mgorny updated this revision to Diff 191641.Mar 21 2019, 12:14 AM

Covered more callsites.

labath added inline comments.Mar 21 2019, 1:03 AM
lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
255–258 ↗(On Diff #191641)

IIUC, these only manipulate the options struct, so I don't see how they could fail with EINTR. OTOH, the tcsetattr call below is documented to return EINTR at least on NetBSD http://netbsd.gw.com/cgi-bin/man-cgi?cfsetospeed+3+NetBSD-current.

lldb/tools/debugserver/source/DNB.cpp
173 ↗(On Diff #191641)

You can't use llvm code from debugserver. I am not really sure what darwin-debug is, but the same may be true for that as well. If I were you, I'd just leave these two alone.

lldb/tools/lldb-server/lldb-platform.cpp
319 ↗(On Diff #191641)

I don't think this is necessary here with WNOHANG and everything.

I think this is fine, except for the things I pointed out inline. As for SafelyCloseFileDescriptor (wow) thing, I think we should use that, given that it's already there. I suggest making a separate patch for that.

mgorny updated this revision to Diff 191644.Mar 21 2019, 1:38 AM
mgorny marked 5 inline comments as done.
mgorny retitled this revision from [lldb] [WIP/RFC] Add missing retries on EINTR to [lldb] Add missing EINTR handling.
mgorny edited the summary of this revision. (Show Details)

Thanks for the review. Addressed comments.

lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
255–258 ↗(On Diff #191641)

Yeah, that's why I covered it, though it looks surprising to me as well. But looking at the code, it can't happen really, so I'll just revert this.

lldb/tools/lldb-server/lldb-platform.cpp
319 ↗(On Diff #191641)

Yep, sorry, missed this one.

labath added inline comments.Mar 21 2019, 1:43 AM
lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
255–258 ↗(On Diff #191641)

I think we misunderstood each other. My expectation would be that these two calls don't need EINTR protection, but the tcsetattr call (line 267) does.

lldb/tools/lldb-server/lldb-platform.cpp
22 ↗(On Diff #191644)

revert this part too?

mgorny marked 3 inline comments as done.Mar 21 2019, 3:58 AM
mgorny added inline comments.
lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
255–258 ↗(On Diff #191641)

I'm not sure if it can happen with TCSANOW but I guess better safe than sorry.

mgorny updated this revision to Diff 191657.Mar 21 2019, 3:59 AM
mgorny marked an inline comment as done.

Applied requested changes.

Now, the curious thing is that so far I have 2 more test failures with this. I'll investigate closer, maybe it's just flakiness.

labath accepted this revision.Mar 21 2019, 10:38 AM
labath added inline comments.
lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
255–258 ↗(On Diff #191641)

Ah, OK, I see. I am not really familiar with this syscall, so if you are reasonably confident that this particular combo of arguments cannot block (and be interrupted), then I'm fine with leaving the EINTR loop out.

This revision is now accepted and ready to land.Mar 21 2019, 10:38 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2019, 12:36 PM