refactor: move unsafe send sync impl up to Context#14805
Conversation
|
Because of unsafe impl<T: UserEvent> Send for DispatcherMainThreadContext<T> {}
#[derive(Clone)]
pub struct DispatcherMainThreadContext<T: UserEvent> {
pub window_target: EventLoopWindowTarget<Message<T>>,
pub web_context: WebContextStore,
// changing this to an Rc will cause frequent app crashes.
pub windows: Arc<WindowsStore>,
#[cfg(feature = "tracing")]
pub active_tracing_spans: ActiveTraceSpanStore,
}there's another change necessary, originally missed. Maybe it is still unsound that |
Package Changes Through 6c29e7bThere are 2 changes which include tauri-runtime-wry with minor, tauri-bundler with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
742458d to
9bf1b7f
Compare
|
As the broken CI on wry PR 1657 shows, that fix was a bit optimistic. I don't know when I can further look into this, but I've pushed a fix that pulls the unsafety at least to the internals of Tauri instead of exposing it publically. Maybe this is enough of an improvement to be merged? Summarizing, tauri currently exposes unsoundness in its public api, we might be interested in merging something that breaks as little as possible to fix this, this is such a minimal suggestion. The fact that std::thread::spawn(move || match new_window_req_handler(uri, features) { ... }); |
| } | ||
| } | ||
|
|
||
| unsafe impl<T: UserEvent> Send for Context<T> {} |
There was a problem hiding this comment.
The way this moved the unsafe Send and Sync impl to Context makes sense to me
| @@ -428,14 +431,6 @@ pub enum ActiveTracingSpan { | |||
| #[derive(Debug)] | |||
| pub struct WindowsStore(pub RefCell<BTreeMap<WindowId, WindowWrapper>>); | |||
There was a problem hiding this comment.
I think maybe we can do this the thing I did in 021476b
There was a problem hiding this comment.
Can we elaborate on this in another PR? I don't have the bandwidth except to see this merged.
|
This would probably fix #10001 |
|
#10001 is different that it's a panic on |
|
Might make sense to close it? |
Context
Fixes #14801
Depends on wry PR 1657.
I'm not intimately familiar with what is going on in this code, so I'm using heuristics to guide my fix:
fn on_eventfrom thePlugintrait are not SyncWindowsStoreis sandwiched between two types that are both not Sync, it contains types that are not Sync and it itself is contained inand
of which the last is not Sync.
For basic soundness based on the examples in #14801 if a non-Sync field is public in a public struct that struct must be not Sync as well.
We have two choices, make both these structs that contain public
WindowsStoresSyncor make them both not Sync. Attempting to make both of these structsSyncis a rat's nest, so let's take the alternative, let's assume they must be both not Sync. This implies the Sync impl of bothWindowsStoreandDispatcherMainThreadContextare mistaken.Removing the Sync impl of
DispatcherMainThreadContextleads to another rat's nest of errors.Contextused to inherit Sync based on its fields, so removing Sync fromDispatcherMainThreadContextmakes it not Sync as well.I can't reason whether
Contextshould or should not be Sync, but in any case we are overriding Sync "at the edges" of the code, so there is a larger space in which the absence of Sync will be caught by the compiler.In summary, these changes strictly reduce the ways to be unsound. More cases are caught that were previously not sound.