5271: Time out for POST requests too (hopefully fixes #5198) r=heinrich5991 a=def-

Untested because the issue is sporadic. But I think it makes sense to have a timeout even if this is not the root cause.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-05-31 08:01:38 +00:00 committed by GitHub
commit 760cb99574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 7 deletions

View file

@ -1733,7 +1733,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
str_format(aUrl, sizeof(aUrl), "%s/%s", UseConfigUrl ? g_Config.m_ClMapDownloadUrl : m_aMapDownloadUrl, aEscaped);
m_pMapdownloadTask = HttpGetFile(aUrl, Storage(), m_aMapdownloadFilenameTemp, IStorage::TYPE_SAVE);
m_pMapdownloadTask->Timeout(CTimeout{g_Config.m_ClMapDownloadConnectTimeoutMs, g_Config.m_ClMapDownloadLowSpeedLimit, g_Config.m_ClMapDownloadLowSpeedTime});
m_pMapdownloadTask->Timeout(CTimeout{g_Config.m_ClMapDownloadConnectTimeoutMs, 0, g_Config.m_ClMapDownloadLowSpeedLimit, g_Config.m_ClMapDownloadLowSpeedTime});
Engine()->AddJob(m_pMapdownloadTask);
}
else
@ -4638,7 +4638,7 @@ void CClient::RequestDDNetInfo()
// Use ipv4 so we can know the ingame ip addresses of players before they join game servers
m_pDDNetInfoTask = HttpGetFile(aUrl, Storage(), m_aDDNetInfoTmp, IStorage::TYPE_SAVE);
m_pDDNetInfoTask->Timeout(CTimeout{10000, 500, 10});
m_pDDNetInfoTask->Timeout(CTimeout{10000, 0, 500, 10});
m_pDDNetInfoTask->IpResolve(IPRESOLVE::V4);
Engine()->AddJob(m_pDDNetInfoTask);
}

View file

@ -166,7 +166,7 @@ void CChooseMaster::CJob::Run()
//
// 10 seconds connection timeout, lower than 8KB/s for 10 seconds to
// fail.
CTimeout Timeout{10000, 8000, 10};
CTimeout Timeout{10000, 0, 8000, 10};
int aTimeMs[MAX_URLS];
for(int i = 0; i < m_pData->m_NumUrls; i++)
{
@ -339,7 +339,7 @@ void CServerBrowserHttp::Update()
}
m_pGetServers = HttpGet(pBestUrl);
// 10 seconds connection timeout, lower than 8KB/s for 10 seconds to fail.
m_pGetServers->Timeout(CTimeout{10000, 8000, 10});
m_pGetServers->Timeout(CTimeout{10000, 0, 8000, 10});
m_pEngine->AddJob(m_pGetServers);
m_State = STATE_REFRESHING;
}

View file

@ -195,6 +195,7 @@ int CHttpRequest::RunImpl(CURL *pUser)
curl_easy_setopt(pHandle, CURLOPT_ERRORBUFFER, aErr);
curl_easy_setopt(pHandle, CURLOPT_CONNECTTIMEOUT_MS, m_Timeout.ConnectTimeoutMs);
curl_easy_setopt(pHandle, CURLOPT_TIMEOUT_MS, m_Timeout.TimeoutMs);
curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_LIMIT, m_Timeout.LowSpeedLimit);
curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_TIME, m_Timeout.LowSpeedTime);

View file

@ -34,6 +34,7 @@ enum class IPRESOLVE
struct CTimeout
{
long ConnectTimeoutMs;
long TimeoutMs;
long LowSpeedLimit;
long LowSpeedTime;
};
@ -53,7 +54,7 @@ class CHttpRequest : public IJob
unsigned char *m_pBody = nullptr;
size_t m_BodyLength = 0;
CTimeout m_Timeout = CTimeout{0, 0, 0};
CTimeout m_Timeout = CTimeout{0, 0, 0, 0};
REQUEST m_Type = REQUEST::GET;
bool m_WriteToFile = false;
@ -168,7 +169,7 @@ inline std::unique_ptr<CHttpRequest> HttpGetFile(const char *pUrl, IStorage *pSt
{
std::unique_ptr<CHttpRequest> pResult = HttpGet(pUrl);
pResult->WriteToFile(pStorage, pOutputFile, StorageType);
pResult->Timeout(CTimeout{4000, 500, 5});
pResult->Timeout(CTimeout{4000, 0, 500, 5});
return pResult;
}
@ -176,6 +177,7 @@ inline std::unique_ptr<CHttpRequest> HttpPost(const char *pUrl, const unsigned c
{
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->Post(pData, DataLength);
pResult->Timeout(CTimeout{4000, 15000, 500, 5});
return pResult;
}
@ -183,6 +185,7 @@ inline std::unique_ptr<CHttpRequest> HttpPostJson(const char *pUrl, const char *
{
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->PostJson(pJson);
pResult->Timeout(CTimeout{4000, 15000, 500, 5});
return pResult;
}

View file

@ -42,7 +42,7 @@ CSkins::CGetPngFile::CGetPngFile(CSkins *pSkins, const char *pUrl, IStorage *pSt
m_pSkins(pSkins)
{
WriteToFile(pStorage, pDest, IStorage::TYPE_SAVE);
Timeout(CTimeout{0, 0, 0});
Timeout(CTimeout{0, 0, 0, 0});
LogProgress(HTTPLOG::NONE);
}