DioxusLabs / DioxusLabs/dioxus
Subsecond hotpatch doesn't preserve mutable global variable address in hotpatched crate.
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
The address of mutable global variables in current crate changes after hotpatch.
**Steps To Reproduce**
Steps to reproduce the behavior:
I tested wasm, windows native and Linux(WSL) native. In all platforms the issue exists.
Example native webserver
```rust
use axum::routing::{get, post};
use dioxus_devtools::subsecond;
use futures::FutureExt;
use std::env;
use std::sync::atomic::AtomicUsize;
use std::sync::{Arc, LazyLock, Mutex};
#[tokio::main]
async fn main() {
dioxus_devtools::connect_subsecond();
router_main().await;
}
async fn router_main() {
use axum::{routing::get, Router};
let app = Router::new().route("/", get(test_route));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
println!("Server running on http://localhost:3000");
axum::serve(listener, app.clone()).await.unwrap()
}
async fn test_route() -> axum::response::Html {
get_str().into()
}
static LOCAL_DATA: AtomicUsize = AtomicUsize::new(0);
fn get_str() -> String {
subsecond::call(|| {
format!(
"testB. curr crate data addr {:?}\nvalue {:?}",
(&LOCAL_DATA) as *const AtomicUsize,
LOCAL_DATA.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
)
})
}
```
Use `curl localhost:3000` (in windows `curl.exe`) multiple times, change the "testA" to "testB", curl again, the address of mutable global `LOCAL_DATA` changes:
```
curl.exe localhost:3000
testA. curr crate data addr 0x7ff7e6a75fd8
value 0
curl.exe localhost:3000
testA. curr crate data addr 0x7ff7e6a75fd8
value 1
curl.exe localhost:3000
testA. curr crate data addr 0x7ff7e6a75fd8
value 2
curl.exe localhost:3000
testB. curr crate data addr 0x7fffec5550f8
value 0
```
Similar thing also happens in Wasm.
**Expected behavior**
Mutable global variable address should not change. This behavior breaks many things that rely on mutable global.
**Screenshots**
**Environment:**
- Dioxus version: 0.7.3
- Rust version: rustc 1.91.1
- OS info: Tested that it occurs in Windows native, WSL and wasm. Possibly apply to all platforms.
- App platform:
**Questionnaire**
The global data imported from other crates have stable address. This issue only applies to the hotpached crate's own global data.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.