-
Notifications
You must be signed in to change notification settings - Fork 957
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
transports/{tcp,dns,websocket}: Remove Clone implementation for *Config #2682
Conversation
This commit removes the `Clone` implementation on `GenTcpConfig` and consequently the `Clone` implementations on `GenDnsConfig` and `WsConfig`. When port-reuse is enabled, `GenTcpConfig` tracks the addresses it is listening in a `HashSet`. This `HashSet` is shared with the `TcpListenStream`s via an `Arc<Mutex<_>>`. Given that `Clone` is `derive`d on `GenTcpConfig`, cloning a `GenTcpConfig`, results in both instances sharing the same set of listen addresses. This is not intuitive. This behavior is for example error prone in the scenario where one wants to speak both plain DNS/TCP and Websockets. Say a user creates the transport in the following way: ``` Rust let transport = { let tcp = tcp::TcpConfig::new().nodelay(true).port_reuse(true); let dns_tcp = dns::DnsConfig::system(tcp).await?; let ws_dns_tcp = websocket::WsConfig::new(dns_tcp.clone()); dns_tcp.or_transport(ws_dns_tcp) }; ``` Both `dns_tcp` and `ws_dns_tcp` share the set of listen addresses, given the `dns_tcp.clone()` to create the `ws_dns_tcp`. Thus, with port-reuse, a Websocket dial might reuse a DNS/TCP listening port instead of a Websocket listening port. With this commit a user is forced to do the below, preventing the above error: ``` Rust let transport = { let dns_tcp = dns::DnsConfig::system(tcp::TcpConfig::new().nodelay(true).port_reuse(true)).await?; let ws_dns_tcp = websocket::WsConfig::new( dns::DnsConfig::system(tcp::TcpConfig::new().nodelay(true).port_reuse(true)).await?, ); dns_tcp.or_transport(ws_dns_tcp) }; ```
Note that the above scenario is not very likely. |
Related discussion: #2652 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Description
This commit removes the
Clone
implementation onGenTcpConfig
and consequently theClone
implementations on
GenDnsConfig
andWsConfig
.When port-reuse is enabled,
GenTcpConfig
tracks the addresses it is listening in aHashSet
. ThisHashSet
is shared with theTcpListenStream
s via anArc<Mutex<_>>
. Given thatClone
isderive
d onGenTcpConfig
, cloning aGenTcpConfig
, results in both instances sharing the sameset of listen addresses. This is not intuitive.
This behavior is for example error prone in the scenario where one wants to speak both plain DNS/TCP and
Websockets. Say a user creates the transport in the following way:
Both
dns_tcp
andws_dns_tcp
share the set of listen addresses, given thedns_tcp.clone()
tocreate the
ws_dns_tcp
. Thus, with port-reuse, a Websocket dial might reuse a DNS/TCP listeningport instead of a Websocket listening port.
With this commit a user is forced to do the below, preventing the above error:
Links to any relevant issues
Follow up on #2670 //CC @Pj50
Open Questions
Change checklist