-
-
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
Intermittent segfault on program exit #3441
Comments
Please explain why you believe that this is a diesel issue and not a issue in some of the underlying dependencies. Especially as the segfault is pointing to a different crate ( |
It could be an r2d2 issue. It's diesel::r2d2, so I reported it here. I'll open a ticket on the r2d2 repo. I dropped the static linking, it still happens. |
Can you provide a self contained docker image where the issue happens? |
I added a Dockerfile and docker-compose, but now I can't reproduce the segfault. That means somehow the issue is related to my local environment. How does diesel choose what libpq to link with? Maybe it's using a different version on my system versus in the Dockerfile. I tried installing libpq-dev the same way on my local machine the docker container, but it didn't change anything. |
sfackler from r2d2 responded here: sfackler/r2d2#137 There's no unsafe code in r2d2, so this is definitely a diesel issue. Note that the crash doesn't happen if I comment out either of the min_idle or max_size lines:
|
I've tried to reproduce that locally with the provided code and I cannot reproduce this issue after a few hundredth runs. Seems like this is really dependent on your environment. Again it would be really helpful to reproduce it in a docker container. Also as you seem to be sure that this is a diesel issue: Please explain why you believe this is the case, otherwise this can also be caused by libpq.
If you link libpq dynamically you can just use |
I would wager on it being an issue in one of the C dependencies of diesel. It's just a broader surface area for crashes. https://raw.githubusercontent.com/eloff/diesel-segfault/main/coredump.png
|
It looks like an openssl issue:
|
How stable is https://github.com/weiznich/diesel_async? That could be one way to side-step the issue. |
Yes the backtrace indicates that this is openssl related. Might be related to #813 Please double check that your libpq uses the same openssl version as other parts of your application.
I do consider that crate as experimental. |
Bringing in the latest openssl crate (0.10.43) for rust as an explicit dependency, and calling openssl::init() at the top of main() to disable the openssl atexit handler fixes the crash. Maybe that's something diesel could do? This recent commit to openssl rust here is the one that fixes it: https://github.com/sfackler/rust-openssl/pull/1649/files#r1040260747, I guess I have openssl 111b on my machine. I checked under the debugger that it is that line being executed that disables the atexit handler. |
I'm happy to hear that you figured out a solution for this problem 👍 . I don't think it would be a good idea to add an explicit call to
I would like to close this issue as environment specific issue. |
Fair enough, I think if others have this problem, they'll find this github issue and can follow the same step to resolve it (add openssl as explicit dependency, call openssl::init() at the top of main()). |
Closed as this is not considered to be an issue in diesel itself. I would consider that to be an libpq issue, so it might be worth to report this upstream? That written: I would really like to see a pure rust postgres connection implementation as third party crate extending diesel. If someone is interested in working and maintaining such a crate, please reach out. I would estimate that this can be done in a 500-1000 lines of code by wrapping the existing |
Just wanted to post here and note that we've been experiencing this issue as an intermittent failure in our integration tests for months. Just today, we isolated it to Diesel... then discovered this issue. @eloff I will buy you a drink if you are ever passing through NYC. As an additional data point, we use MySQL—we've never experienced it in our production Docker container (based on Thank you again 🙏🏼 Cheers! |
@thomasmost If your case is mysql related that's likely not related to this issue. If you have a minimal reproducible example, please open a new issue containing that example so that we can track down the actual issue. |
The openssl::init fix seems to solve it though... Are you sure? |
@thomasmost Yes it would be good to have. In the worst case it's only for documentation purposes, but even there it might be helpful. |
Okay I'll work on an MVR |
I had the exact same problem, but in my case initializing ssl before the failing code didn't fix it. If this is also the case for anyone else, check if you're statically linking openssl by setting the vendored cargo feature, and if you are, disable this. It seems like there can be a version incompatibility between libpq's openssl and the one embedded in your binary. |
I'm getting an intermittent seg fault on program exit in something to do with a Postgres db connection in some scheduled-thread-pool thread.
Setup
Versions
rustc 1.65.0 (897e37553 2022-11-02)
2.0.2
(PostgreSQL) 15.1 (Ubuntu 15.1-1.pgdg20.04+1)
Ubuntu 20.04 5.15.0-56-generic
Feature Flags
diesel = { version="2.0.2", features=["postgres","r2d2","uuid","chrono"] }
Problem Description
Seg fault in scheduled-thread-pool in some connection run() method. I'm working on creating a less intermittent reproduction that I can share.
What are you trying to accomplish?
What is the expected output?
What is the actual output?
Are you seeing any additional errors?
Steps to reproduce
Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: