diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-07-22 22:12:17 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-07-22 22:12:17 +0100 |
commit | 21fb56dc4a8cb6f8d442d96fa5f0b600ef15403b (patch) | |
tree | 2ed5f63a78e1c56b2452afef7ddc11943ac676bc /net/server_select.lua | |
parent | b442c597977063fd641c12aedc21c162685295db (diff) | |
download | prosody-21fb56dc4a8cb6f8d442d96fa5f0b600ef15403b.tar.gz prosody-21fb56dc4a8cb6f8d442d96fa5f0b600ef15403b.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/server_select.lua')
-rw-r--r-- | net/server_select.lua | 25 |
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 |