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

Fix ipv6 connection hangs when in v4 environment #1734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ayanamist
Copy link

@ayanamist ayanamist commented Nov 28, 2022

Since connection will be reset to USE_IPV4_IPV6_RANDOM when connection failed even in pure v4 environment.

if (currentDatacenter->isRepeatCheckingAddresses() && (ConnectionsManager::getInstance(currentDatacenter->instanceNum).getIpStratagy() == USE_IPV4_ONLY || ConnectionsManager::getInstance(currentDatacenter->instanceNum).getIpStratagy() == USE_IPV6_ONLY)) {
if (LOGS_ENABLED) DEBUG_D("started retrying connection, set ipv4 ipv6 random strategy");
ConnectionsManager::getInstance(currentDatacenter->instanceNum).setIpStrategy(USE_IPV4_IPV6_RANDOM);
}

However, it does not reset lastProtocolUsefullData correctly if connectionType is not ConnectionTypeGeneric (usually problem occurs when ConnectionTypeGenericMedia) and lastProtocolUsefullData will be set false only here.

} else if (strategy == USE_IPV4_IPV6_RANDOM) {
if (ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolUsefullData) {
ipv6 = ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolIsIpv6 ? TcpAddressFlagIpv6 : 0;
} else {
uint8_t value;
RAND_bytes(&value, 1);
ipv6 = value % 3 == 0 ? TcpAddressFlagIpv6 : 0;
ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolIsIpv6 = ipv6 != 0;
}
if (connectionType == ConnectionTypeGeneric) {
ConnectionsManager::getInstance(currentDatacenter->instanceNum).lastProtocolUsefullData = false;
}
} else {

So it always connect as ipv6 if lastProtocolUsefullData is true and RAND_bytes got 0, 3, 6 even there is no ipv6 capability.

I try to fix it using always reset lastProtocolUsefullData to false when USE_IPV4_IPV6_RANDOM is meet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant