Skip to content

Commit

Permalink
workaround openssl shutdown race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Mar 23, 2023
1 parent 2f6032b commit 44a0819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libssh-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libssh-rs"
version = "0.1.6"
version = "0.1.7"
edition = "2018"
repository = "https://github.com/wez/libssh-rs"
description = "Bindings to the libssh library"
Expand All @@ -12,6 +12,10 @@ license = "MIT"
bitflags = "1.3"
libssh-rs-sys = { version = "0.1.3", path = "../libssh-rs-sys" }
thiserror = "1.0"
# Pinned on this last version with openssl-src-300 until a newer release
# is made that unblocks it.
# <https://github.com/sfackler/rust-openssl/pull/1578>
openssl-sys = "=0.9.71"

[features]
vendored = ["libssh-rs-sys/vendored"]
Expand Down
11 changes: 11 additions & 0 deletions libssh-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ pub use crate::sftp::*;
struct LibraryState {}
impl LibraryState {
pub fn new() -> Option<Self> {
// Force openssl to initialize.
// In theory, we don't need this, but in practice we do because of
// this bug:
// <https://github.com/openssl/openssl/issues/6214>
// which weirdly requires that *all* openssl threads be joined before
// the process exits, which is an unrealistic expectation on behalf
// of that library.
// That was worked around in openssl_sys:
// <https://github.com/sfackler/rust-openssl/pull/1324>
// which tells openssl to skip the process-wide shutdown.
openssl_sys::init();
let res = unsafe { sys::ssh_init() };
if res != sys::SSH_OK as i32 {
None
Expand Down

0 comments on commit 44a0819

Please sign in to comment.