Always dialing in parallel and reusing instead of closing
Dialing and caching at layer 4 for reuse by TLS, ZTLS
During the investigation, we concluded that the methods implemented in this PR might not fit the use case and created new issues. This led to the new implementation in #287, informed by our learnings from this PR.
Dialing in a single goroutine will not work as we create approximately 10,000 new connections per minute in Golang. Dialing in parallel and caching all connections can cause issues with synchronization and predictive caching.
Caching connections can often lead to the error 'use of closed network connection'. This error occurs when TCP keep-alive is not set or expires. While we can enforce this on the client side, servers usually reject any keep-alive requests that last more than 10 seconds [observed on a case-to-case basis during testing].
The scope of caching and reusing is relevant and only helpful in the first 10 seconds of its usage.
Dialing in parallel and synchronization introduces a worker goroutine and related leaks.
Proposed Changes
During the investigation, we concluded that the methods implemented in this PR might not fit the use case and created new issues. This led to the new implementation in #287, informed by our learnings from this PR.