From 1f4a84edc271adb8901dfbefaecc33d2c392ae04 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 6 Apr 2017 11:57:28 +0800 Subject: [PATCH] fix dns bug , see issue #605 --- examples/main.lua | 2 ++ lualib/dns.lua | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/main.lua b/examples/main.lua index 5a2150db..1b371707 100644 --- a/examples/main.lua +++ b/examples/main.lua @@ -9,6 +9,7 @@ skynet.start(function() if not skynet.getenv "daemon" then local console = skynet.newservice("console") end +--[[ skynet.newservice("debug_console",8000) skynet.newservice("simpledb") local watchdog = skynet.newservice("watchdog") @@ -18,5 +19,6 @@ skynet.start(function() nodelay = true, }) skynet.error("Watchdog listen on", 8888) +]] skynet.exit() end) diff --git a/lualib/dns.lua b/lualib/dns.lua index 318ba4c1..76f363f0 100644 --- a/lualib/dns.lua +++ b/lualib/dns.lua @@ -87,6 +87,7 @@ local weak = {__mode = "kv"} local CACHE = {} local dns = {} +local request_pool = {} function dns.flush() CACHE[QTYPE.A] = setmetatable({},weak) @@ -113,7 +114,21 @@ end local next_tid = 1 local function gen_tid() local tid = next_tid - next_tid = next_tid + 1 + if request_pool[tid] then + tid = nil + for i = 1, 65535 do + -- find available tid + if not request_pool[i] then + tid = i + break + end + end + assert(tid) + end + next_tid = tid + 1 + if next_tid > 65535 then + next_tid = 1 + end return tid end @@ -205,7 +220,6 @@ local function unpack_rdata(qtype, chunk) end local dns_server -local request_pool = {} local function resolve(content) if #content < DNS_HEADER_LEN then