Software /
code /
prosody
Diff
net/server_select.lua @ 4980:2e35cfe11835
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.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Jul 2012 22:12:17 +0100 |
parent | 4962:1d8fb12a9b2d |
child | 4982:07f478b1f7c0 |
line wrap: on
line diff
--- a/net/server_select.lua Sun Jul 22 18:52:20 2012 +0100 +++ b/net/server_select.lua Sun Jul 22 22:12:17 2012 +0100 @@ -314,17 +314,17 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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