I am using actix-web and bb8 and gettign the following error
That looks bad. Try running it in a debugger to see what is crashing. cargo run
prints a path to the executable it runs. Pass that to lldb
or gdb
.
To elaborate on the reply of @kornel:
To get a backtrace using gdb
or lldb
, you can use
$ gdb /path/to/executable
(gdb) run
(gdb) bt
$ lldb /path/to/executable
(lldb) run
(lldb) bt
It was a wrong implementation of From<Row>
for my User
struct
If that implementation doesn't use unsafe
code, that means that there is still a bug somewhere. What was the wrong implementation? And what crate does Row
originate from?
Row
belongs use tokio-postgres
I implemented From<Row> for User
then implemented From<&Row> for User
and in the function I just used &row.into() which suprisingly didnt cause any compiletime issues.
when I copy paste my From implementation adding an & in front of everything it works.
Doesnt this look more of a rust issue rather than tokio-postgres ? couse of the error was the from trait implementation which didnt have a single line of code from tokio-postgres
Is your program open-source? If so a link to the crashing version would be helpful.
It is not but with not much effort I believe I can create a small example
Thanks! That would be really useful.
I have created a very minimal example which is probably nonsense as a beginner initially it made sense to me though :D.
#[derive(Debug)]
struct Foo;
#[derive(Debug)]
struct Bar;
impl From<Bar> for Foo {
fn from(_: Bar) -> Self {
Self
}
}
impl<T: From<Bar>> From<&T> for Foo {
fn from(t: &T) -> Self {
t.into()
}
}
fn main() {
let a = &Bar;
let _: Foo = dbg!(a.into());
}
I run this using x86_64-unknown-linux-musl if that makes any difference
Thanks for reducing the code. When I run it, I get a stack overflow:
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Rust should register a SIGSEGV handler to detect stack overflows, but it seems that it didn't trigger in your case. This makes this a lot less worrying, as the SIGSEGV handler only exists to give a nicer crash message. A stack overflow is guaranteed to hit a SIGSEGV rather than overwriting random data due to stack probing. This means that stack overflows are not exploitable.
Oh I see It makes a lot of sense.
Is there any way of implementing something for both From and From<&T> without duplicating the entire impl block ?
You will probably want to do the actual work in From<&T>
and then either just leave out the From<T>
and let users do Foo::from(&val)
or val.into()
(later implicitly adds &
) or let From<T>
dispatch to From<&T>
.
I see thanks a lot for the stackoverflow info I dont know why I just see a segviolation message instead of a proper stack overflow trace in a debug build
The musl targets don't have a complete implementation of Rust's stack guard:
That explains why there was no stack overflow message. I was looking at the SIGSEGV handler and couldn't find a musl special case, so I assumed musl wasn't the reason.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.