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

Tcp transport port_reuse_dialing test missing some assert #2651

Closed
Tracked by #2662
stormshield-pj50 opened this issue May 16, 2022 · 4 comments
Closed
Tracked by #2662

Tcp transport port_reuse_dialing test missing some assert #2651

stormshield-pj50 opened this issue May 16, 2022 · 4 comments
Labels
bug priority:important The changes needed are critical for libp2p, or are blocking another project

Comments

@stormshield-pj50
Copy link
Contributor

Summary

The port_reuse_dialing test in transports/tcp/lib.rs seems to be incomplete, it does not check for port reuse.

Expected behaviour

In this test the dialer outgoing connection must reuse the listener port. So an assert like this should be added near line 930 in the port_reuse_dialing/dialer function:

assert!(tcp.port_reuse.local_dial_addr(&listener.listen_addr.ip()).is_some());

Actual behaviour

The assert is missing and if I add it it fails. It seems to be a consequence of the commit 2ad905f. Previously the listen_addrs field in PortReuse was a Arc<RwLock<HashSet<(IpAddr, Port)>>> so it could be shared between GenTcpConfig and TcpListenStream. One ugly work around to make the assert pass in the test is to clone listener.port_reuse into tcp:

tcp.port_reuse = listener.port_reuse.clone(); 

Possible Solution

Don't know if only the test is broken or if libp2p port reuse feature is also broken.

Would you like to work on fixing this bug?

Yes

@mxinden
Copy link
Member

mxinden commented May 17, 2022

Thanks for the bug report @Pj50. Great job catching this! This was my mistake.

For others following along here is where the HashMap instead of the Arc is being cloned.

TcpListenStream::<T>::new(socket.into(), self.port_reuse.clone())

Would you like to work on fixing this bug?

Yes

Great! Let me know in case you need any help.

@mxinden
Copy link
Member

mxinden commented May 22, 2022

Friendly ping @Pj50. Still interested in providing a patch?

@stormshield-pj50
Copy link
Contributor Author

Sorry being late for a patch, I had to work on other topics last week. Working on it now.

stormshield-pj50 added a commit to stormshield-pj50/rust-libp2p that referenced this issue May 23, 2022
stormshield-pj50 added a commit to stormshield-pj50/rust-libp2p that referenced this issue May 25, 2022
stormshield-pj50 added a commit to stormshield-pj50/rust-libp2p that referenced this issue May 25, 2022
stormshield-pj50 added a commit to stormshield-pj50/rust-libp2p that referenced this issue May 30, 2022
@mxinden
Copy link
Member

mxinden commented May 30, 2022

Closing here with #2670 merged.

@mxinden mxinden closed this as completed May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug priority:important The changes needed are critical for libp2p, or are blocking another project
Projects
None yet
Development

No branches or pull requests

2 participants