try to use HttpCompletionOption.ResponseHeadersRead again

This commit is contained in:
UbitUmarov
2026-03-11 18:52:49 +00:00
parent d3f314b292
commit f785a45418
5 changed files with 316 additions and 139 deletions

View File

@@ -34,9 +34,11 @@ using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Web;
namespace OpenSim.Services.Connectors
@@ -747,7 +749,7 @@ namespace OpenSim.Services.Connectors
if (string.IsNullOrEmpty(obj))
{
m_log.Warn($"[XInventory]: empty post data");
return new Dictionary<string, object>();
return [];
}
Dictionary<string, object> respDic = null;
@@ -757,6 +759,8 @@ namespace OpenSim.Services.Connectors
HttpResponseMessage responseMessage = null;
HttpRequestMessage request = null;
HttpClient client = null;
bool bodyTimedOut = false;
try
{
client = WebUtil.GetNewGlobalHttpClient(m_requestTimeout);
@@ -789,13 +793,26 @@ namespace OpenSim.Services.Connectors
if ((responseMessage.Content.Headers.ContentLength is long contentLength) && contentLength != 0)
{
rcvlen = (int)contentLength;
respDic = ServerUtils.ParseXmlResponse(responseMessage.Content.ReadAsStream());
using Stream respStream = responseMessage.Content.ReadAsStream();
using (CancellationTokenSource cts = new(WebUtil.EstimatedReceiveTimeout(responseMessage.Content.Headers, true)))
{
_ = cts.Token.Register(() =>
{
bodyTimedOut = true;
respStream?.Close();
});
rcvlen = (int)contentLength;
respDic = ServerUtils.ParseXmlResponse(respStream);
}
}
}
catch (Exception e)
{
m_log.Info($"[XInventory]: Error receiving response from {m_InventoryURL}: {e.Message}");
if(bodyTimedOut)
m_log.Info($"[XInventory]: TImeout on receiving POST response from {m_InventoryURL}");
else
m_log.Info($"[XInventory]: Error receiving response from {m_InventoryURL}: {e.Message}");
throw;
}
finally
@@ -806,7 +823,11 @@ namespace OpenSim.Services.Connectors
}
ticks = Util.EnvironmentTickCountSubtract(ticks);
if (ticks > WebUtil.LongCallTime)
if(bodyTimedOut)
{
m_log.Info($"[XInventory]: POST receive timeout {m_InventoryURL} ({ticks}ms)");
}
else if (ticks > WebUtil.LongCallTime)
{
m_log.Info($"[XInventory]: POST {m_InventoryURL} took {ticks}ms {sendlen}/{rcvlen}bytes");
}