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

realloc(): invalid pointer #22

Closed
omus opened this issue Mar 12, 2019 · 11 comments · Fixed by #23
Closed

realloc(): invalid pointer #22

omus opened this issue Mar 12, 2019 · 11 comments · Fixed by #23

Comments

@omus
Copy link
Member

omus commented Mar 12, 2019

When updating from Parsers 0.2.18 to 0.2.20 I get the following when parsing a CSV file:

realloc(): invalid pointer

signal (6): Aborted
in expression starting at no file:0
gsignal at /lib64/libc.so.6 (unknown line)
abort at /lib64/libc.so.6 (unknown line)
__libc_message at /lib64/libc.so.6 (unknown line)
malloc_printerr at /lib64/libc.so.6 (unknown line)
realloc at /lib64/libc.so.6 (unknown line)
jl_gc_counted_realloc_with_old_size at /buildworker/worker/package_linux64/build/src/gc.c:2777
__gmpz_realloc at /usr/local/julia/bin/../lib/julia/libgmp.so (unknown line)
__gmpz_mul_2exp at /usr/local/julia/bin/../lib/julia/libgmp.so (unknown line)
mul_2exp! at ./gmp.jl:146 [inlined]
mul_2exp! at ./gmp.jl:148 [inlined]
scale at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:96 [inlined]
scale at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:114 [inlined]
#_defaultparser#46 at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:255 [inlined]
_defaultparser at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:126 [inlined]
#defaultparser#45 at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:123 [inlined]
defaultparser at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:123 [inlined]
#parse!#13 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:349 [inlined]
parse! at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:349 [inlined]
#parse!#29 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:644 [inlined]
parse! at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:642 [inlined]
#parse!#28 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:618 [inlined]
parse! at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:616 [inlined]
#parse!#27 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:572 [inlined]
parse! at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:547 [inlined]
#parse!#26 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:448 [inlined]
parse! at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:448 [inlined]
#parse#15 at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:351 [inlined]
parse at /root/.julia/packages/Parsers/v5u2B/src/Parsers.jl:351 [inlined]
parsefield at /root/.julia/packages/CSV/eWuJV/src/tables.jl:88 [inlined]
getproperty at /root/.julia/packages/CSV/eWuJV/src/tables.jl:182
getproperty at /root/.julia/packages/CSV/eWuJV/src/tables.jl:148 [inlined]
macro expansion at /root/.julia/packages/Tables/qIlOP/src/utils.jl:55 [inlined]
eachcolumn at /root/.julia/packages/Tables/qIlOP/src/utils.jl:47 [inlined]
buildcolumns at /root/.julia/packages/Tables/qIlOP/src/fallbacks.jl:95
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
columns at /root/.julia/packages/Tables/qIlOP/src/fallbacks.jl:149 [inlined]
Type at /root/.julia/packages/DataFrames/IKMvt/src/other/tables.jl:21
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
|> at ./operators.jl:813
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
#read#105 at /root/.julia/packages/CSV/eWuJV/src/CSV.jl:315
unknown function (ip: 0x7fa269275a4b)
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
#read at ./none:0
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1831
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
...

I'll note that this error is occurring in a fairly deep application. I can try to make a minimal reproducible test if requested.

@ararslan
Copy link
Member

Seems likely to have been introduced by #20, based on the backtrace.

@quinnj
Copy link
Member

quinnj commented Mar 12, 2019

I just ran all the CSV.jl tests and didn't see any issues; is there a way you could share the file, even if only privately? (quinn.jacobd@gmail.com)

@omus
Copy link
Member Author

omus commented Mar 12, 2019

I'll try to pull the data tomorrow

@quinnj
Copy link
Member

quinnj commented Mar 12, 2019

@simonbyrne, do you have any ideas on what might be happening here? My two thoughts are

  • are we doing something bad w/ the mutating operations here? not accounting for things growing when they're not supposed to or something?
  • are we getting some weird precompile issue (since we pre-allocate the NUMS that get used during scale) and their pointers are somehow getting invalidated/corrupt and then we try to resize them?

@simonbyrne
Copy link

The second one could be the case. Tough to say without a reproducible example.

@omus
Copy link
Member Author

omus commented Mar 18, 2019

It appears that the issue has to do with using PackageCompiler. I can reproduce the problem by running the tests for Parsers. The issue can be reproduced using this Dockerfile:

FROM julia:1.0.3-stretch

RUN apt-get update && apt-get install -y gcc && \
    julia -e 'using Pkg; Pkg.add("PackageCompiler"); using PackageCompiler; compile_package(force=true)'

RUN julia -e 'using Pkg, PackageCompiler; Pkg.add(PackageSpec(name="Parsers", version="0.2.20"))'

# Fails with "Task cannot be serialized"
# RUN julia -e 'using PackageCompiler; compile_package("Parsers", force=true)'

RUN echo "using Parsers" > userimg.jl && \
    julia -e 'using PackageCompiler: build_sysimg, default_sysimg_path; build_sysimg(default_sysimg_path(), "userimg.jl")'

CMD ["julia", "-e", "using Pkg; Pkg.test(\"Parsers\")"]
$ docker build -t parsers .
...

$ docker run --rm parsers
...
*** Error in `/usr/local/julia/bin/julia': realloc(): invalid next size: 0x00007f0cb087c4d0 ***
...
signal (6): Aborted
in expression starting at /root/.julia/packages/Parsers/v5u2B/test/floats.jl:1
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f0cb58d8bff)
unknown function (ip: 0x7f0cb58defc5)
unknown function (ip: 0x7f0cb58e213b)
realloc at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
jl_gc_counted_realloc_with_old_size at /buildworker/worker/package_linux64/build/src/gc.c:2777
__gmpz_realloc at /usr/local/julia/bin/../lib/julia/libgmp.so (unknown line)
__gmpz_mul at /usr/local/julia/bin/../lib/julia/libgmp.so (unknown line)
mul! at ./gmp.jl:132 [inlined]
mul! at ./gmp.jl:134 [inlined]
scale at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:80 [inlined]
scale at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:114 [inlined]
#_defaultparser#46 at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:239 [inlined]
_defaultparser at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:126 [inlined]
#defaultparser#45 at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:123 [inlined]
defaultparser at /root/.julia/packages/Parsers/v5u2B/src/floats.jl:123
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
...

Using Parsers 0.2.18 does not have this issue.

@iamed2
Copy link

iamed2 commented Mar 18, 2019

@omus So if you enable the commented-out line, it fails to compile, but with sysimg it succeeds compilation but gives the realloc error at runtime?

@omus
Copy link
Member Author

omus commented Mar 18, 2019

Using the following to include Parsers.jl in a system image will fail on 0.2.20 or 0.2.18:

RUN julia -e 'using PackageCompiler; compile_package("Parsers", force=true)'

Like you said, the alternative build_sysimg allows compilation to succeed but gives the realloc error at runtime.

@quinnj
Copy link
Member

quinnj commented Mar 18, 2019

So if I'm understanding correctly, when Parsers.jl is included in the sysimg, the pre-allocated BigInts are somehow borked, but normal precompilation is fine. Right?

@omus
Copy link
Member Author

omus commented Mar 18, 2019

So if I'm understanding correctly, when Parsers.jl is included in the sysimg, the pre-allocated BigInts are somehow borked, but normal precompilation is fine. Right?

That is also my understanding

@JeffBezanson
Copy link

You can't mutate BigInts in the system image. Since this use case needs resize_nthreads! in __init__ anyway, might as well initialize the global BigInts there.

quinnj added a commit that referenced this issue Mar 18, 2019
…unction. This caused issues when Parsers.jl was included in the sysimg compilation (via PackageCompiler).
quinnj added a commit that referenced this issue Mar 18, 2019
Fix #22 by reinitializing our pre-allocated BigInts in the __init__ f…
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 a pull request may close this issue.

6 participants