Skip to content

Commit d2f2e29

Browse files
committed
call socket.abandon while auth error, see issue cloudwu#355
1 parent d7e4e43 commit d2f2e29

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lualib/snax/loginserver.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ end
4949

5050
local function launch_slave(auth_handler)
5151
local function auth(fd, addr)
52-
fd = assert(tonumber(fd))
5352
skynet.error(string.format("connect from %s (fd = %d)", addr, fd))
5453
socket.start(fd)
5554

@@ -84,11 +83,11 @@ local function launch_slave(auth_handler)
8483

8584
local ok, server, uid = pcall(auth_handler,token)
8685

87-
socket.abandon(fd)
8886
return ok, server, uid, secret
8987
end
9088

91-
local function ret_pack(ok, err, ...)
89+
local function ret_pack(fd, ok, err, ...)
90+
socket.abandon(fd)
9291
if ok then
9392
skynet.ret(skynet.pack(err, ...))
9493
else
@@ -100,8 +99,12 @@ local function launch_slave(auth_handler)
10099
end
101100
end
102101

103-
skynet.dispatch("lua", function(_,_,...)
104-
ret_pack(pcall(auth, ...))
102+
skynet.dispatch("lua", function(_,_,fd,...)
103+
if type(fd) ~= "number" then
104+
skynet.ret(skynet.pack(false, "invalid fd type"))
105+
else
106+
ret_pack(fd,pcall(auth, fd, ...))
107+
end
105108
end)
106109
end
107110

0 commit comments

Comments
 (0)