-
Notifications
You must be signed in to change notification settings - Fork 130
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
fix(utils): Remove global buffer used when writing files to disk #442
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good opportunity to slightly expand the relevant KSFileUtils.h
function header documentation to highlight the potential failure mode? On a (minor) related note: bsg_ksfureadBytesFromFD
has an erroneous log message: BSG_KSLOG_ERROR("Could not write to fd...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KSFileUtils_Tests.m
has a commented out test: testWriteBytesToFDBig. Should this be reinstated, or removed at the same time as this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an implicit (via the now-removed buffer declaration) 64K limit on the size of the passed in data that's been removed with this change. Is it worth stating/checking the expected size limits of passed in data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What alternative approaches (to removing the buffer) have been considered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concurrency, but related to the previous point: is there any possibility that an error in one thread's write()
halfway through another's could affect operation? Are we safe avoiding semaphore's etc. in this case?
Rebasing to apply the changes from #441, removing the erroneously documented functions.
This actually tested one of the unused functions, so its going away too.
I'd say no, because write(2) is smart enough to handle this case, and if any bytes remain after calling
Hopefully no:
|
write(2) already intelligently handles buffering/writing, so this buffer is unneeded in addition to being unsafe for the user-initiated reporting case. The buffer was added in kstenerud/KSCrash@be9bedb and thus the original intent is lost to the mists.
3f7fdf5
to
e906449
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments - LGTM.
Fixes a case where shared memory buffer is used for writing to disk in a code path which can be accessed concurrently from multiple threads. Triggering the error on write requires calling notify from multiple threads at once while
suspendThreadsForUserReported
is disabled.This change removes the buffer altogether, opting for a simpler solution where the system determines how/when to buffer when writing to disk. The buffer was added in kstenerud/KSCrash@be9bedb so the original intent is somewhat lost to the mists.
Tests
Tests for this are a bit fiddly since the issue is timing-based, though its possible to see the effect when using the reproduction case in #401 while setting
suspendThreadsForUserReported = NO
. Added an automated test for this case which would previously fail intermittently, as well as testing manually on iOS 12 / 13.