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

Invalid memory access on Alpine Linux #354

Closed
snacks02 opened this issue Feb 9, 2023 · 12 comments
Closed

Invalid memory access on Alpine Linux #354

snacks02 opened this issue Feb 9, 2023 · 12 comments

Comments

@snacks02
Copy link

snacks02 commented Feb 9, 2023

Sometimes Ameba randomly fails in GitHub Actions with:

image

ci.yml:

name: GitHub Actions

on: push

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    container:
      image: crystallang/crystal:latest-alpine
    steps:
      - uses: actions/checkout@v3
      - run: shards install
      - run: bin/ameba
      - run: crystal tool format --check
      - run: crystal spec

shard.yml:

development_dependencies:
  ameba:
    github: crystal-ameba/ameba
    version: ~> 1.4.0

Rerunning fixes the issue, but would be great to fix this this in Ameba.

Happy to provide additional information if needed.

@Sija
Copy link
Member

Sija commented Feb 9, 2023

Perhaps using alpine (musl) might have sth to do with it?

@snacks02
Copy link
Author

snacks02 commented Feb 9, 2023

Probably so. Never had it happen on Arch with glibc.

@Sija
Copy link
Member

Sija commented Feb 10, 2023

I'd suggest trying with a regular crystal:latest image and checking whether it exhibits the same behaviour to begin with.
Regardless, this is most likely Crystal bug, not ameba's.

@Sija
Copy link
Member

Sija commented Feb 10, 2023

In any case it would be good to debug it further and eventually report the buggy behaviour to the crystal's issue tracker instead.

@jwoertink
Copy link

Just got this issue on Cable https://github.com/cable-cr/cable/actions/runs/4774224693/jobs/8487769812?pr=69

 Postinstall of ameba: make bin && make run_file
Failed postinstall of ameba on make bin && make run_file:
shards build -Dpreview_mt
Dependencies are satisfied
Building: ameba
Error target ameba failed to compile:
Showing last frame. Use --error-trace for full trace.

In src/ameba/rule/base.cr:142:10

 142 | {{ run("../../contrib/read_type_doc",
          ^--
Error: Error executing run (exit code: 11): ../../contrib/read_type_doc QueryBoolMethods /__w/cable/cable/lib/ameba/src/ameba/rule/style/query_bool_methods.cr


stderr:

    Error while trying to determine if a stack overflow has occurred. Probable memory corruption
    Invalid memory access (signal 11) at address 0x38
    [0x55caacd58e56] ?? +94328971431510 in /github/home/.cache/crystal/__w-cable-cable-lib-ameba-src-contrib-read_type_doc.cr/macro_run
    [0x55caacd58e1a] ?? +94328971431450 in /github/home/.cache/crystal/__w-cable-cable-lib-ameba-src-contrib-read_type_doc.cr/macro_run
    [0x7ff58ba73c9f] ?? +140692586708127 in /lib/ld-musl-x86_64.so.1


make: *** [Makefile:9: build] Error 1
Error: Process completed with exit code 1.

Seems it only happened on Crystal 1.6. I'm also using crystallang/crystal:${{ matrix.crystal_version }}-alpine, so I'll give that a shot to try not using alpine.

@jwoertink
Copy link

Confirmed, taking off the -alpine fixed it 👍

@snacks02 snacks02 changed the title Invalid memory access in GitHub Actions Invalid memory access on Alpine Linux May 23, 2023
@Sija Sija pinned this issue May 30, 2023
@daliborfilus
Copy link
Contributor

Using ameba (alpine base) build crashes on our CI too, this is our latest crash:

$ ameba
Error while trying to determine if a stack overflow has occurred. Probable memory corruption
Invalid memory access (signal 11) at address 0x38
[0x55c44399fd36] *Exception::CallStack::print_backtrace:Nil +118 in /usr/bin/ameba
[0x55c4439845f6] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil) +310 in /usr/bin/ameba
[0x7f10416735f0] ?? +139707793487344 in /lib/ld-musl-x86_64.so.1

but only once in a week. 99% of the time it works.
We have our own ameba docker alpine image built using:

FROM alpine:edge as builder
RUN apk add --update crystal shards yaml-dev musl-dev make
RUN mkdir /ameba
WORKDIR /ameba
COPY . /ameba/
RUN make clean && make

FROM alpine:latest
RUN apk add --update yaml pcre2 gc libevent libgcc
RUN mkdir /src
WORKDIR /src
COPY --from=builder /ameba/bin/ameba /usr/bin/
RUN ameba -v
ENTRYPOINT [ "/usr/bin/ameba" ]

The image is rebuilt every day using these:

build:
  stage: build
  script:
    # clone to subdirectory "ameba"
    - git clone --depth=1 https://github.com/crystal-ameba/ameba.git ameba
    # add our patched Dockerfile
    - cp Dockerfile ameba/Dockerfile
    - cd ameba
    # build
    - docker build --pull -t "${CI_REGISTRY_IMAGE}:latest" .
    # push
    - docker push "${CI_REGISTRY_IMAGE}:latest"

(The Dockerfile is based of ameba's Dockerfile.)

@HertzDevil
Copy link

Please check if crystal-lang/crystal#15043 fixes this

@snacks02
Copy link
Author

@HertzDevil Thanks! This only happens occasionally, so maybe the issue can be closed for now and reopened if someone complains.

@Sija
Copy link
Member

Sija commented Oct 11, 2024

Since Crystal 1.14 is out now, can you possibly try it out and confirm whether the issue is actually fixed?

/cc @jwoertink @daliborfilus @snacks02

@Sija Sija unpinned this issue Oct 11, 2024
@jwoertink
Copy link

@Sija yup! This fixed the original issue I had. I was able to add -alpine back and everything built and ran 👍

@Sija
Copy link
Member

Sija commented Oct 11, 2024

Great! Now we just need to wait for alpine maintainers to update crystal package for alpine:edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants