feat: Re-query the DNS during reconnection#798
Closed
franktz wants to merge 1 commit intoithewei:masterfrom
Closed
feat: Re-query the DNS during reconnection#798franktz wants to merge 1 commit intoithewei:masterfrom
franktz wants to merge 1 commit intoithewei:masterfrom
Conversation
ithewei
reviewed
Jan 15, 2026
|
|
||
| int startConnect() { | ||
| if (channel == NULL || channel->isClosed()) { | ||
| // Re-resolve DNS to get the latest IP address |
Owner
There was a problem hiding this comment.
I suggest to add if (reconn_setting && reconn_setting->cur_retry_cnt > 1) to use the old address on the first reconnection to speed up the reconnection process.
Owner
There was a problem hiding this comment.
int connfd = -1;
if (reconn_setting && reconn_setting->cur_retry_cnt > 1) {
connfd = createsocket(remote_port, remote_host.c_str());
} else {
connfd = createsocket(&remote_addr.sa);
}
ithewei
pushed a commit
that referenced
this pull request
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
中文:
在 WebSocket 长连接场景中此功能尤为重要。
启用 reconn_setting_t 重连接功能后,客户端在重新建立连接时会再次进行 DNS 查询,以获取最新的 IP 地址,从而避免因 DNS 切换导致无法连接服务的问题。该机制通常用于同一域名下主从 IP 切换的重连场景:先完成 DNS 切换,再停止旧服务,使连接在重连时能够成功接入新的服务节点。
English:
This mechanism is especially critical for WebSocket long-lived connections and is strongly recommended to be enabled.
When the reconn_setting_t reconnection feature is enabled, the client performs a DNS lookup again during reconnection to obtain the latest IP address. This prevents connection failures caused by DNS changes. This mechanism is commonly used in reconnection scenarios involving primary/secondary IP switching under the same domain name: the DNS is switched first, then the old service is stopped, allowing the reconnection to successfully connect to the new service node.