Skip to content
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 CSV.Chunks crashing due to finalized buffer #763

Merged
merged 1 commit into from
Oct 29, 2020
Merged

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Oct 29, 2020

Fixes #734. The issue here is that on windows, we aggressively finalize
the file source buffer as a way to "close" the file, since windows is
much more picky when trying to modify an mmapped file after parsing.
i.e. windows complains if you try to modify a file and there's still an
mmap reference to it somewhere, so at the end of CSV.File, we call
finalize(buf) to ensure it gets unmapped. The problem, however, is
that CSV.Chunks calls CSV.File multiple times on the same buf,
providing different starting/ending byte positions to read in chunks.
So naturally, after the first chunk was read, the buffer was getting
finalized and then the 2nd chunk immediately crashed trying to read its
chunk from a finalized buffer.

Fixes #734. The issue here is that on windows, we aggressively finalize
the file source buffer as a way to "close" the file, since windows is
much more picky when trying to modify an mmapped file after parsing.
i.e. windows complains if you try to modify a file and there's still an
mmap reference to it somewhere, so at the end of CSV.File, we call
`finalize(buf)` to ensure it gets unmapped. The problem, however, is
that `CSV.Chunks` calls `CSV.File` multiple times on the same `buf`,
providing different starting/ending byte positions to read in chunks.
So naturally, after the first chunk was read, the buffer was getting
finalized and then the 2nd chunk immediately crashed trying to read its
chunk from a finalized buffer.
@codecov
Copy link

codecov bot commented Oct 29, 2020

Codecov Report

Merging #763 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #763   +/-   ##
=======================================
  Coverage   85.57%   85.57%           
=======================================
  Files          10       10           
  Lines        1948     1948           
=======================================
  Hits         1667     1667           
  Misses        281      281           
Impacted Files Coverage Δ
src/chunks.jl 100.00% <100.00%> (ø)
src/file.jl 94.74% <100.00%> (ø)
src/header.jl 95.27% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d05682...f40ba1f. Read the comment docs.

@quinnj quinnj merged commit 2ffb4b1 into master Oct 29, 2020
@quinnj quinnj deleted the jq/chunksfix branch October 29, 2020 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSV.Chunks crashing on large CSV
1 participant