From e08ca7402cd8fb81424d80405496d8064bec539d Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 24 Jul 2020 19:19:16 +0100 Subject: [PATCH] reduce default http keepalive to just 30s because to viewers connections flood. --- .../OSHttpServer/ContextTimeoutManager.cs | 14 +++++----- .../OSHttpServer/HttpClientContext.cs | 26 ++++++------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/ContextTimeoutManager.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/ContextTimeoutManager.cs index ceea624c31..55c7a77323 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/ContextTimeoutManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/ContextTimeoutManager.cs @@ -276,22 +276,24 @@ namespace OSHttpServer if (context.TriggerKeepalive) { context.TriggerKeepalive = false; - context.MonitorKeepaliveStartMS = nowMS + 1; + context.MonitorKeepaliveStartMS = nowMS + 500; return false; } if (context.MonitorKeepaliveStartMS != 0) { + if (context.IsClosing) + { + disconnectError = SocketError.Success; + return true; + } + if (EnvironmentTickCountAdd(context.TimeoutKeepAlive, context.MonitorKeepaliveStartMS) < nowMS) { - if(context.IsClosing) - disconnectError = SocketError.Success; - else - disconnectError = SocketError.TimedOut; + disconnectError = SocketError.TimedOut; context.MonitorKeepaliveStartMS = 0; return true; } - return false; } if (EnvironmentTickCountAdd(context.TimeoutMaxIdle, context.LastActivityTimeMS) < nowMS) diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs index a1b6342c7a..66bb75b131 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpClientContext.cs @@ -46,7 +46,7 @@ namespace OSHttpServer public int TimeoutRequestReceived = 30000; // 30 seconds public int TimeoutMaxIdle = 180000; // 3 minutes - public int m_TimeoutKeepAlive = 60000; + public int m_TimeoutKeepAlive = 30000; public bool FirstRequestLineReceived; public bool FullRequestReceived; @@ -444,7 +444,7 @@ namespace OSHttpServer if (m_maxRequests == 0) return; - if(--m_maxRequests == 0) + if (--m_maxRequests == 0) m_currentRequest.Connection = ConnectionType.Close; if(m_currentRequest.Uri == null) @@ -527,8 +527,7 @@ namespace OSHttpServer if(contextID < 0) return; - bool doclose = ctype == ConnectionType.Close; - if (doclose) + if (ctype == ConnectionType.Close) { m_isClosing = true; m_requests.Clear(); @@ -538,30 +537,21 @@ namespace OSHttpServer else { LastActivityTimeMS = ContextTimeoutManager.EnvironmentTickCount(); - if (Stream != null && Stream.CanWrite) - { - ContextTimeoutManager.ContextEnterActiveSend(); - try - { - await Stream.FlushAsync().ConfigureAwait(false); - } - catch - { - }; - ContextTimeoutManager.ContextLeaveActiveSend(); - } - if (Stream == null || !Stream.CanWrite) return; - TriggerKeepalive = true; HttpRequest nextRequest = null; lock (m_requestsLock) { if (m_requests != null && m_requests.Count > 0) nextRequest = m_requests.Dequeue(); if (nextRequest != null && RequestReceived != null) + { m_waitingResponse = true; + TriggerKeepalive = false; + } + else + TriggerKeepalive = true; } if (nextRequest != null) RequestReceived?.Invoke(this, new RequestEventArgs(nextRequest));