Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different waker_vtable addresses for same type #2864

Closed
timotheyca opened this issue Jun 14, 2024 · 5 comments · Fixed by #2865
Closed

Different waker_vtable addresses for same type #2864

timotheyca opened this issue Jun 14, 2024 · 5 comments · Fixed by #2865

Comments

@timotheyca
Copy link
Contributor

use futures::task::ArcWake;

struct Temp;

impl ArcWake for Temp {
    fn wake_by_ref(arc_self: &std::sync::Arc<Self>) {
        let _ = arc_self;
    }
}

fn main() {
    let temp = std::sync::Arc::new(Temp);
    let waker = futures::task::waker_ref(&temp);
    println!("{waker:?} {:?}", waker.clone());
    futures::executor::block_on(async {});
}

Sometimes (more often than not, in my experience), when running in --release mode, vtable addresses don't match:

WakerRef { waker: ManuallyDrop { value: Waker { data: 0x5654d35e5b90, vtable: 0x5654d2ad62b8 } }, _marker: PhantomData<&()> } Waker { data: 0x5654d35e5b90, vtable: 0x5654d2ad6308 }

Why this matters: this leads to AtomicWaker and alike to clone (or, worse, wake) on each poll because of how Waker::will_wake compares Wakers. Example: sdroege/async-tungstenite#133

Is this a compiler bug? If yes, can we do something to mitigate it?

@taiki-e
Copy link
Member

taiki-e commented Jun 14, 2024

Same issue as #2829 (comment) / rust-lang/rust#121622 (comment)?

@timotheyca
Copy link
Contributor Author

yes, seems to be the same issue

@timotheyca
Copy link
Contributor Author

timotheyca commented Jun 14, 2024

#[inline(always)] on clone_arc_raw has some positive effect on the situation sometimes (ref_wake_same passes?)

@sdroege
Copy link
Contributor

sdroege commented Jun 15, 2024

Quoting myself from

[...] this sounds like a bug in the code doing the comparison. If multiple codegen units are involved, it's not guaranteed that the vtable is always the same for the same object.

That's why e.g. https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.ptr_eq exists.

@taiki-e
Copy link
Member

taiki-e commented Oct 1, 2024

Resolved by #2865

@taiki-e taiki-e closed this as completed Oct 1, 2024
@taiki-e taiki-e linked a pull request Oct 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants