aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-07-22 22:12:17 +0100
committerMatthew Wild <mwild1@gmail.com>2012-07-22 22:12:17 +0100
commit689b6f19a0e986598a364f8692d4af31de2c388b (patch)
tree2ed5f63a78e1c56b2452afef7ddc11943ac676bc /net
parentd0fd520b7bb57186f29f5c090569b9712f2ef6bd (diff)
downloadprosody-689b6f19a0e986598a364f8692d4af31de2c388b.tar.gz
prosody-689b6f19a0e986598a364f8692d4af31de2c388b.zip
net.server_select: Never call ondisconnect() directly, go via handler:close() or handler:force_close() - fixes cases where ondisconnect() could be called multiple times for the same connection, leading to issues with s2sout retry logic.
Diffstat (limited to 'net')
-rw-r--r--net/server_select.lua25
1 files changed, 11 insertions, 14 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index c0f8742e..990188a1 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -314,17 +314,17 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
end
return false, "setoption not implemented";
end
- handler.force_close = function ( self )
+ handler.force_close = function ( self, err )
if bufferqueuelen ~= 0 then
- out_put("discarding unwritten data for ", tostring(ip), ":", tostring(clientport))
+ out_put("server.lua: discarding unwritten data for ", tostring(ip), ":", tostring(clientport))
for i = bufferqueuelen, 1, -1 do
bufferqueue[i] = nil;
end
bufferqueuelen = 0;
end
- return self:close();
+ return self:close(err);
end
- handler.close = function( self )
+ handler.close = function( self, err )
if not handler then return true; end
_readlistlen = removesocket( _readlist, socket, _readlistlen )
_readtimes[ handler ] = nil
@@ -353,7 +353,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
local _handler = handler;
handler = nil
if disconnect then
- disconnect(_handler, false);
+ disconnect(_handler, err or false);
+ disconnect = nil
end
end
if server then
@@ -456,8 +457,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
local buffer = buffer or part or ""
local len = string_len( buffer )
if len > maxreadlen then
- disconnect( handler, "receive buffer exceeded" )
- handler:close( true )
+ handler:close( "receive buffer exceeded" )
return false
end
local count = len * STAT_UNIT
@@ -469,8 +469,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
else -- connections was closed or fatal error
out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) )
fatalerror = true
- disconnect( handler, err )
- _ = handler and handler:close( )
+ _ = handler and handler:force_close( err )
return false
end
end
@@ -509,8 +508,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
else -- connection was closed during sending or fatal error
out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) )
fatalerror = true
- disconnect( handler, err )
- _ = handler and handler:force_close( )
+ _ = handler and handler:force_close( err )
return false
end
end
@@ -552,9 +550,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
end
end
out_put( "server.lua: ssl handshake error: ", tostring(err or "handshake too long") )
- disconnect( handler, "ssl handshake failed" )
- _ = handler and handler:force_close()
- return false, err -- handshake failed
+ _ = handler and handler:force_close("ssl handshake failed")
+ return false, err -- handshake failed
end
)
end