Skip to content

Conversation

@ch3pjw
Copy link

@ch3pjw ch3pjw commented Nov 11, 2025

This PR adds an unsafe impl of Sync for RouterIntoService

Motivation

Whilst trying to build some testing apparatus for my project, I wanted to pass a reference to something containing RouterIntoService<Body> by reference into an async method. Doing so made the Future for that method not Send, because RouterIntoService<Body> was not Sync. This was problematic for me, so I looked into your source and found that the body type B was only held onto as aPhantomData, which to my mind means it shouldn't affect the Sync-ness of the data structure. Looking further into the state type S, that looks like it's used in a dyn trait bound who's super traits already force Send and Sync, so I believe there's not a requirement on S to be Sync here either, but I might be mistaken on that.

Solution

I just added a manual implementation to relax the !Sync constraint on the type. This should mean that in the future I don't need to manually annotate the types in my code.

Copy link
Member

@jplatte jplatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we should adjust the PhantomData we use. Definitely don't want to add this unsafe impl. I'll look into this soon(-ish).

@jplatte
Copy link
Member

jplatte commented Nov 14, 2025

A different fix has been merged in #3555. I'll probably make another patch release with that, soon.

@ch3pjw
Copy link
Author

ch3pjw commented Nov 17, 2025

Ah nice, that looks great, thank you very much 🙏

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 this pull request may close these issues.

2 participants