Closed guzuomuse closed 1 year ago
i can confirm it not a windows
issue yet not a rust
issue, it is a 'crate' issue.
why?
let me create a nats connection from scratch:
rust code:
use std::net::TcpStream;
use std::slice;
pub extern "C" fn create_nats_conn_with_tcpstream(address: *mut u16) -> *mut TcpStream {
let address = convert_u16_to_string(address);// address->:tcp://localhost:4222
let tcp_stream = TcpStream::connect(address).unwrap();
Box::into_raw(Box::new(tcp_stream))
}
// pub extern "C" fn close_tcp_conn(tcp_stream:*mut TcpStream){
// unsafe{
// let _=Box::from_raw(tcp_stream);
// };
// }
this code works fine .we can see the conn established with 'nats-top'. even this connection is closed. it will not crash the mt5 software.
but if you want to publish the message ..subscribe message we must do everything from scratch.that's say we can not use this crate.we must create a new crate like the nats.rs
does.
Make sure that these boxes are checked before submitting your issue -- thank you!
NATS version (
grep 'name = "nats"' Cargo.lock -A 1
)nats --version 0.0.34 nats.rs version :0.24.0
rustc version (
rustc --version
- we support Rust 1.41 and up)rustc --version rustc 1.67.0 (fc594f156 2023-01-24)
OS/Container environment:
Windows10
Steps or code to reproduce the issue:
let me explain how to reproduce.
i want to build a dll libray using this crate for communicating with Metatrade5(a well known trading software.let's call it
mt5
for short) so first we create a dll using rust.the code above do nothing just export a
create_nats_conn
function which take a*mut u16
parameter because the mt5 using string in u16 format. next,let 's call the dll in mt5 script a namedmql5
language for mt5. bellow is the script code:run the script and then we can use the
nats-top
command from windows cmd. we can see we have conn created by rust.after 5 seconds the script closed. as described in the mql5 script: we still can see the connection listed the
nats-top
. cuase.the connection will keep about 2 minutes. and wait for about 2 minutes the mt5 software crashed!!!!!!!Expected result:
expected result is : we can close the connection manually by create a dll exported function using
Box::from_raw(...)
and even connection closed implicitly after 2 minutes . it should'nt crash the mt5 software.Actual result:
connection closed and crash the mt5 software.
by a mention : i think the reason why the connection still keep abount 2mints is that ,we have this code in this crate:
// const PING_INTERVAL: Duration = Duration::from_secs(2 * 60);
which located in src/client.rs