Skip to content

Commit c04f332

Browse files
author
elviswu
committed
fix dns.cc中可能存在的多线程问题(在两个GetHostByName请求中产生的dnsinfo.thread_id相等)
1 parent b9cc907 commit c04f332

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

mars/comm/dns/dns.cc

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ struct dnsinfo {
4646
int status;
4747
};
4848

49+
static std::string DNSInfoToString(const struct dnsinfo& _info) {
50+
XMessage msg;
51+
msg(TSF"info:%@p, threadid:%_, dns:@%p, host_name:%_, status:%_", &_info, _info.threadid, _info.dns, _info.host_name, _info.status);
52+
return msg.Message();
53+
}
4954
static std::vector<dnsinfo> sg_dnsinfo_vec;
5055
static Condition sg_condition;
5156
static Mutex sg_mutex;
@@ -231,12 +236,23 @@ bool DNS::GetHostByName(const std::string& _host_name, std::vector<std::string>&
231236
}
232237

233238
if (kGetIPSuc == it->status) {
234-
ips = it->result;
235-
236-
if (_breaker) _breaker->dnsstatus = NULL;
237-
238-
sg_dnsinfo_vec.erase(it);
239-
return true;
239+
if (_host_name==it->host_name) {
240+
ips = it->result;
241+
242+
if (_breaker) _breaker->dnsstatus = NULL;
243+
244+
sg_dnsinfo_vec.erase(it);
245+
return true;
246+
} else {
247+
std::vector<dnsinfo>::iterator iter = sg_dnsinfo_vec.begin();
248+
int i = 0;
249+
for (; iter != sg_dnsinfo_vec.end(); ++iter) {
250+
xerror2(TSF"sg_info_vec[%_]:%_", i++, DNSInfoToString(*iter));
251+
}
252+
//TODO 监控
253+
xassert2(false, TSF"_host_name:%_, it->host_name:%_", _host_name, it->host_name);
254+
return false;
255+
}
240256
}
241257

242258
if (kGetIPTimeout == it->status || kGetIPCancel == it->status || kGetIPFail == it->status) {

0 commit comments

Comments
 (0)