Retain references to buffers while doing blocking I/O #742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@olafhering, #726 was actually a symptom of a small family of pretty serious bugs in Lwt. Some Lwt APIs were not retaining references to user buffers that were passed in for I/O, and the buffers were occasionally being released too early.
These bugs are fairly difficult to trigger, as they require:
When triggered, Lwt could access dead (or reallocated) memory when writing, and unexpectedly write to memory of other objects when reading. The buggy APIs were
Lwt_unix.writev
,Lwt_unix.readv
,Lwt_bytes.write
,Lwt_bytes.read
.Lwt_bytes.wait_mincore
also had the issue, even though it's a different kind of function.I added a new kind of tests specifically for buffer retention, and reviewed the arguments of all functions in
lwt.unix
for whether they have this bug or not.I ran the same stress test that I used to reproduce #726 locally, and did not observe the problem with these patches. I'll run it a few more times, and then merge.
@olafhering, thanks again for being thorough and reporting the issue.
Fixes #726.