-
Notifications
You must be signed in to change notification settings - Fork 133
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
RUMM-506 Prevent malforming payload due to I/O exception #133
RUMM-506 Prevent malforming payload due to I/O exception #133
Conversation
…e to I/O Exception
…esNotMalformTheFileContent` test green
@ncreated i just noticed that in some cases the log has |
note: we still can't figure out why we will ship this hotfix version and keep monitoring the issue |
I added the test to prevent also malformations in the middle of the file: 792c74c This is to additionally check if the |
i suspect that when can we add something like this? func append(transaction: ((Data) throws -> Void) throws -> Void) throws {
let fileHandle = try FileHandle(forWritingTo: url)
var errorThrown = true
let initialOffset = fileHandle.offsetInFile
defer {
let finalOffset = fileHandle.offsetInFile
if errorThrown && (initialOffset != finalOffset) {
fileHandle.moveTheEndOfFile(to: initialOffset) // this should fix it but i don't know how we can do this safely
}
fileHandle.closeFile()
}
...
errorThrown = false
} EDIT: snippet changed to a potential fix from monitoring the issue |
@buranmert even if it works, this does neither fix the problem nor empower us with reporting. I think it's better to iterate on this issue and first see if we'll be receiving malformed logs after applying this hotfix. WDYT? |
yes, fixing null char issue doesn't seem trivial; let's go with this hotfix and keep monitoring 👍 |
What and why?
🐛 Some payloads send from SDK were malformed.
The reason was not performing writes atomically:
In rare cases, when the
I/O
exception was thrown for the second write, it was leaving the file's content malformed.How?
The fix is to perform atomic writes:
The red unit test for payload malformation was added, then it was made green with a fix.
Later improvements
The
File
interface is not resistant for this sort of bugs, as it doesn't perform transactional write even if it looks like:As this requires additional refactoring, to not impact the hotfix scope, I will open a separate PR changing the
WritableFile
interface from:to simply:
Review checklist