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

Signal 11 segmentation fault on Alpine but not macOS #21765

Open
ejstembler opened this issue Jun 30, 2024 · 1 comment
Open

Signal 11 segmentation fault on Alpine but not macOS #21765

ejstembler opened this issue Jun 30, 2024 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@ejstembler
Copy link

ejstembler commented Jun 30, 2024

Describe the bug

I wrote a small app which connects to my AWS Postgres database to perform a few selects. This works fine on my Intel Mac mini macOS (14.5 23F79). However, it crashes towards the end when ran inside an Alpine Docker container.

Reproduction Steps

import os
import time
import db.pg

const pg_host = os.getenv_opt('DATABASE_HOST') or { panic('DATABASE_HOST not found') }
const pg_user = os.getenv_opt('DATABASE_USER') or { panic('DATABASE_USER not found') }
const pg_pass = os.getenv_opt('DATABASE_PASSWORD') or { panic('DATABASE_PASSWORD not found') }
const pg_db = os.getenv_opt('DATABASE_NAME') or { panic('DATABASE_NAME not found') }

@[table: 'authors']
struct Author {
	id                   int     @[primary; sql: serial]
	name                 string  @[sql_type: 'VARCHAR(65)']
	email                string  @[sql_type: 'VARCHAR(65)']
	social_twitter       ?string @[sql_type: 'VARCHAR(65)']
	social_facebook      ?string @[sql_type: 'VARCHAR(65)']
	social_instagram     ?string @[sql_type: 'VARCHAR(65)']
	social_youtube       ?string @[sql_type: 'VARCHAR(65)']
	social_pinterest     ?string @[sql_type: 'VARCHAR(65)']
	social_linkedin      ?string @[sql_type: 'VARCHAR(65)']
	social_stackoverflow ?string @[sql_type: 'VARCHAR(65)']
	social_gitlab        ?string @[sql_type: 'VARCHAR(65)']
}

@[table: 'books']
struct Book {
	id               int     @[primary; sql: serial]
	slug             ?string @[sql_type: 'VARCHAR(200)']
	category         ?string @[sql_type: 'VARCHAR(25)']
	asin             ?string @[sql_type: 'VARCHAR(10)']
	title            string  @[sql_type: 'VARCHAR(200)']
	product_url      ?string @[sql_type: 'VARCHAR(200)']
	image_url        ?string @[sql_type: 'VARCHAR(200)']
	publication_date string  @[sql_type: 'DATE']
	review           ?string @[sql_type: 'TEXT']
	created_at       string  @[default: 'CURRENT_TIMESTAMP'; sql_type: 'TIMESTAMP']
	goodreads_url    ?string @[sql_type: 'VARCHAR(200)']
}

@[table: 'posts']
struct Post {
	id           int        @[primary; sql: serial]
	author_id    int        @[fkey: 'parent_id']
	slug         string     @[sql_type: 'VARCHAR(256)']
	title        string     @[sql_type: 'VARCHAR(256)']
	summary      ?string    @[sql_type: 'VARCHAR(256)']
	categories   ?string    // Is _text supported?
	tags         ?string    // Is _text supported?
	status       string     @[sql_type: 'VARCHAR(15)']
	view_count   ?int       @[default: 0]
	content_type ?string    @[sql_type: 'VARCHAR(15)']
	content_path ?string    @[sql_type: 'VARCHAR(256)']
	created_at   ?time.Time @[default: 'CURRENT_TIMESTAMP'; sql_type: 'TIMESTAMP']
	updated_at   ?time.Time @[sql_type: 'TIMESTAMP']
	published_at ?time.Time @[sql_type: 'TIMESTAMP']
	last_view_at ?time.Time @[sql_type: 'TIMESTAMP']
}

db := pg.connect(host: pg_host, user: pg_user, password: pg_pass, dbname: pg_db)!

authors_count := sql db {
	select count from Author
}!

println('number of all authors: ${authors_count}')

books_count := sql db {
	select count from Book
}!

println('number of all books: ${books_count}')

scifi_books_count := sql db {
	select count from Book where category == 'science fiction'
}!

println('number of sci-fi books: ${scifi_books_count}')

posts_count := sql db {
	select count from Post
}!

println('number of all posts: ${posts_count}')

published_posts_count := sql db {
	select count from Post where published_at !is none
}!

println('number of all published posts: ${published_posts_count}')

diy_books_count := sql db {
	select count from Book where category == 'diy'
}!

println('number of diy books: ${diy_books_count}')

diy_books := sql db {
	select from Book where category == 'diy'
}!

println('\nDIY books:\n')
for book in diy_books {
	println('${book.id}:\t${book.title}')
}

Expected Behavior

On macOS:

$ dotenv -o -f ".env.heroku" v run src/main.v

number of all authors: 1
number of all books: 321
number of sci-fi books: 16
number of all posts: 141
number of all published posts: 141
number of diy books: 5

DIY books:

73:     Treehouses and other Cool Stuff: 50 Projects You Can Build
90:     Handy Dad: 25 Awesome Projects for Dads and Kids
91:     Geek Dad: Awesomely Geeky Projects and Activities for Dads and Kids to Share
126:    The Handbuilt Home: 34 Simple Stylish and Budget-Friendly Woodworking Projects for Every Room
151:    The Furniture Bible: Everything You Need to Know to Identify, Restore & Care for Furniture

Current Behavior

On Alpine Docker container:

podman run --env-file ".env.heroku" --rm -it v-postgres

number of all authors: 1
number of all books: 321
number of sci-fi books: 16
number of all posts: 141
number of all published posts: 141
number of diy books: 5
signal 11: segmentation fault
backtrace_symbols is missing => printing backtraces is not available.
Some libc implementations like musl simply do not provide it.
make: *** [podmanRun] Error 139

Possible Solution

I'm not sure what is causing the fault on Alpine, though it occurs somewhere in the last bit of code:

diy_books := sql db {
	select from Book where category == 'diy'
}!

println('\nDIY books:\n')
for book in diy_books {
	println('${book.id}:\t${book.title}')
}

Additional Information/Context

Dockerfile:

# Stage 1: Build the V application
FROM thevlang/vlang:latest AS builder

# Install necessary packages for PostgreSQL
RUN apk add --no-cache postgresql-dev

# Set the working directory
WORKDIR /app

# Copy the source code into the container
COPY . .

# Build the V project
RUN v -o app src/main.v

# Stage 2: Create a smaller image with the executable
FROM alpine:latest

# Install necessary packages to run the application with PostgreSQL
RUN apk add --no-cache libpq

ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_NAME
ARG DATABASE_USER
ARG DATABASE_PASSWORD

ENV DATABASE_HOST $DATABASE_HOST
ENV DATABASE_PORT $DATABASE_PORT
ENV DATABASE_NAME $DATABASE_NAME
ENV DATABASE_USER $DATABASE_USER
ENV DATABASE_PASSWORD $DATABASE_PASSWORD

# Set the working directory
WORKDIR /app

# Copy the executable from the builder stage
COPY --from=builder /app/app /app/

# Run the V application
CMD ["./app"]

V version

0.4.6 4a7c70c

Environment details (OS name and version, etc.)

Alpine:latest

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@ejstembler ejstembler added the Bug This tag is applied to issues which reports bugs. label Jun 30, 2024
@ejstembler
Copy link
Author

ejstembler commented Jul 27, 2024

I added code to print the V version when the app runs.

import v.util.version

println(version.v_version)

If I run it locally on macOS I get the current version; even tried this with the new 0.4.7 version.

However, while running from the Docker container (thevlang/vlang:latest builder / alpine:latest runner) the version prints as 0.4.3. Does this mean the thevlang/vlang:latest Docker image is out-of-date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant