-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
segmentation fault on "diesel setup" #700
Comments
Can you provide additional information, such as the version of Diesel CLI you were using, the version of Rust you were using, and whether |
I called diesel in a directory which contains a .env file with DATABASE_URL=postgres://postgres:***@postgres/reminder (of course the pwd is not ***).
diesel_cli v0.10.1 I just noticed that in fact no diesel-command works. Even diesel -v segfaults. That made me wonder whether there is something fishy about my setup, however, compiling a hello-world with rustc works as expected. Anything more I can try? |
If you can give a list of steps I could follow to reproduce that would be helpful. I agree that it's probably something fishy with your setup. Maybe try compiling a program that links diesel without using the CLI? It could also be the loading of one of the c libraries. Do you still see a segfault if you do |
First of all, thanks for your help! The behaviour does not change for I wrote a docker file and a shell script to reproduce the problem. The script starts postgreSQL in a Docker container, then it builds a container with rustup and diesel in it, links it to the postgreSQL instance and opens a root shell into the container. On my machine, Please mind: |
I'm also having segfaults for Steps to reproduce:
When debugging the coredump:
Does that help? |
Hello, RUN apk add postgresql-dev mariadb-dev sqlite-dev musl-dev gdb ARG USERNAME=rust WORKDIR /app/ WORKDIR /app/diesel_demo Then when I build and sh into it I got these: `metres@machine:~/developpement/bidon$ docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it bidon /bin/sh Program received signal SIGSEGV, Segmentation fault. |
So I tried using the rustlang/rust:nightly-buster image and I have no more segfault. So it seems to be related to alpine... |
@megametres Can you try if that reproduces with the latest 1.4.5 release, as this release fixes a potential issue with in the postgres connection setup? |
I figured out that the Cargo.toml provided in my example is never used apart to let the diesel_cli start as it required a Cargo.toml file to exists. The error is generated by diesel_cli which last version is 1.41 But on my personal project, I use the 1.4.5 release and still had the segmentation fault when using Alpine based docker images. |
I can also reproduce in a Docker Alpine image. The Dockerfile itself is quite simple:
I then run the
Trying to establish a connection using Versions: Stack trace:
|
So I've been tracking down the issue to some other discussions and it seems the culprit is According to #2357 and sfackler/rust-openssl#1133, upgrading |
@weiznich Also, |
Dropping
Additionally: That a crate does not receive updates in the last 2 years does not mean that it is out of date or something like that. It's just that That all written: If somebody really want to have a pure rust connection, nobody is going to stop anyone from working on this. We are happy to accept a PR working on that, as long as it addresses those points mentioned above. Additionally diesel is designed in such a way that any thirdparty crate can provide a custom implementation of the |
…h the production docker container back to alpine, but there is an issue with libpq and --target x86_64-unknown-linux-musl, see diesel-rs/diesel#700
It seems this is not yet fixed. With Alpine 3.14, that uses libpq 13.4 as can be seen here I'm stil getting this segmentation fault. I get it both when doing Using the following code: if net::TcpStream::connect(format!("{}:{}", db_host, db_port)).is_ok() {
println!("Connected to the database!");
} else {
panic!("Couldn't connect to the database...");
}
let conn = diesel::pg::PgConnection::establish(&database_url);
println!("Connection OK? {}", conn.is_ok()); I get a "Connected to the database!" output, which means that the TCP connection is well working, but then the I can also see that, for example in 13r0ck/gci-website@a4ed8d0, some projects are having to switch out of using Alpine for their builds and binaries due to missing Diesel support, which is not the ideal solution, since Alpine is a very reasonable distribution for cloud-native applications. Is there any workaround that can make diesel work in Alpine linux? Should this issue stay closed even if |
@Razican It seems very plausible that this can be caused by the incompatibility described in rust-lang/compiler-team#422. In that case there is nothing we can do on diesels side to fix the problem here. As we generally prefer to have open issues only for things that are actionable for contributors (= things you can pick up to work on) that means this issue is closed. Anyway a closed issue does not mean that you cannot discussion things here or report possible solutions or something like that. Additionally we can always reopen a issue as soon as it become actionable because of updated information or because the upstream bug is fixed.
Just to restate the hopefully obvious here: Distributions that dynamically link musl libc (like alpine) are not really supported by upstream rustc in that way that there is not even a target to build for this libraries. You can make it somehow work by using the musl target provided by rustc as long as you statically link everything. Additionally at least for diesel is the musl target a best effort target, which means we do not test there and at least I do not really use that target. This means I do not actively maintain it, as I simply do not have the capacity to test and maintain support all possible compatible rustc targets. I do accept PR's fixing this target so if you are interested in that please submit a PR.
The workaround for any kind of linker issues is always the same: Provide a compatible version of any depended library. In this case this likely requires you to manually build a libpq version that is compatible with rusts static linking of the musl libc. Likely that requires statically linking libpq + openssl as well.
As already elaborated above: Yes this issue should stay closed, as we don't keep open tracking issues to "just" track some upstream bug. |
Thank you for that explanation! Indeed, it was a linking issue. The solution was to link musl dynamically in Alpine by adding the following RUSTFLAGS:
|
@Razican this solution make the image becames very big because it requires libpq openssl-dev musl-dev postgresql-dev to be installed so if the image becames bigger than ubuntu based images so why I will use alpine as a base image? |
Size might not be the main reason for using Alpine. In my case its security and minimalism is much more relevant. |
@Razican yes I agree with you but the size is became the double so you loss the advantage of the small size for the alpine |
@Razican I can see that many pepole menthion this problem and the had to go back and prefer to use ubuntu |
@abdelmonem-mohamed17 Our issue tracker is no discussion forum, so please stop to add unrelated comments about your docker issues here. |
@weiznich It is not a docker problem by the way but anyway thank you for your help. |
hey,
When I run "diesel setup" in the docker container https://hub.docker.com/r/liuchong/rustup/, I get a segmentation fault. A (zipped) core dump is attached.
core.zip
Best,
Alex
The text was updated successfully, but these errors were encountered: