Websocket application crashing on Android


I am writing an Android app and calling into a rust library from Java using JNI. The rust application uses ws-rs for websocket connections.

When the websocket connection is made and when the client tries to send the Handshake message via the TcpStream, a null pointer dereference crash is observed. ws-rs uses mio under the hood and I tried to make the connection non-blocking (as the connect() call sometimes returns EINPROGRESS, just to rule that out. But that didn’t help.

I would appreciate any help.


I don’t know if that’s related, but this code looks very wrong:

#[no_mangle] extern “system” fn receive(mailbox_server: String, …

because you’re using a Rust type with an extern (non-Rust) function. At best the extern part does nothing, but if you’re overwriting the receive symbol used by something else, or something calls it externally, it will crash.

Rust should be warning you about this. Review your warnings (and run cargo clippy for a good measure).


Thank you. Yes, receive wouldn’t need to be an extern “system” function, I made it into a regular rust function and lo and behold, those crashes are gone! (it is hanging somewhere much further down, but that seem unrelated). Thanks again!

1 Like