-
Notifications
You must be signed in to change notification settings - Fork 96
Crashes observed in OutputFileStream due to EXC_BAD_ACCESS. #177
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
Comments
Hi @dcow, the posix API wasn't my first choice, as a matter of fact I didn't find it fun to use at all, haha. The file handle API seems to be changing with every release and I was attempting to shield us from that. I understand regarding some of the issues you point out. Thread synchronization in this case is handled upstream and not sure on the specifics about dubious pointer handling. I had another version of OutputFileStream that used the FileHandle API and ran both through pretty rigorous tests (I had thought). Hammering 10k events each pass, multiple threads writing, etc. Performance numbers showed them to be pretty much identical. As some other pieces were introduced around error handling, etc. I can't just revert the change. If you want to do a PR for OutputFileStream and switch it to use the FileHandle APIs, happy to check that out. I'm definitely not married to the current implementation of that class. If you don't have the will or time, I'll post a PR here in a few days and get your thoughts on it. |
Ignoring the details of which API you're using, we're seeing errors coming from the Segment library. Since we're customers of Segment, this needs to be addressed by your team first and foremost in whatever matter you see fit. In fact, we just saw another one of these errors come in last night. It's affected 4 of our users this past month. The rest was just advice as to what might be causing the errors from our vantage point, take it or leave it. Unfortunately I don't have the cycles right now to throw up a PR, though I wish I could help more. Few quick notes on the posix api:
This allocates contiguous storage for data. The foundation implementation is a little more complicated and elides this step by iterating over the contiguous data regions and writing them one by one. If you're concerned about performance, this might be something to consider adding to your implementation as well.
Which errors are recoverable vs fatal is not something I have time to fully elaborate on right now. Usually something like EINTR (process was interrupted) is recoverable, possibly EIO, but this is where it gets complicated. Anyway, the foundation implementation uses
And a quick note on the general changes that were merged, irrespective of the posix stuff:
Anyway, as you can see this stuff is messy. We use the foundation FileHandle apis too in our product and haven't experienced the deprecation thrashing you have, but maybe we're just lucky. We understand you have other important things to do as well. But at least as consumers of analytics-swift, there appears to be a regression causing crashes for our users. Looking forward to the fix! |
Actually, I just tried it in a playground.
Which yields our error:
|
@bsneed bump. We're seeing an increasing number of these crashes (as more of our users update). |
* Switched OutputFileStream to use FileHandle * updated Storage for OutputFileStream changes * Added unableToClose handler * Fixed test issue w/ parallelized tests. * Removed dead code * Flush memory contents to file before closing. * Fix lack of version callouts. * Added version checks for sync/close
@bsneed thank you! We'll update and report back. |
@dcow thanks so much! Fingers crossed it just goes away now. :D |
Uh oh!
There was an error while loading. Please reload this page.
Recently we've noticed crashes coming from the new OutputFileStream code. An example stack trace is included at the end of this issue.
While digging into this, we noticed the switch from the foundation FileHandle API to the older POSIX API. The rationale presumably is the deprecation of the
write(data: Data)
function. This left us perplexed and we believe this to be a misunderstanding. The specificwrite(data: Data)
function was deprecated, yes, but it was replaced with the genericwrite<T>(contentsOf: T) throws where T : DataProtocol
function. As well as being more flexible in its input parameter, the new function also properly communicates errors viathrows
(related: unhandled exceptions at the write(data: Data) call site was previously an issue we saw coming from your code). It is a welcome replacement (:If I may, it seems the best course of action would be to remove the OutputFileStream addition, specifically, and simply update the code as it was previously so that it uses the non-deprecated write function from FileHandle. And, the new API forces you to handle the errors I mentioned we had also been encountering, 2 birds...
But, if you must stick with the POSIX API, which, while fun to use at times, I would strongly discourage, then the implementation needs some work. There are numerous issues (lack of handling for short writes, unnecessary string conversions, generally thread safety, dubious pointer handling, etc.) which I'm happy to help you through if you decide to stick with this route. But, it's super tricky to get all this right when using the POSIX API hence why the first class Apple-supported Foundation APIs are preferred over the POSIX ones.
The text was updated successfully, but these errors were encountered: