mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
Sentry: use locked contexts to send data to avoid races
This commit is contained in:
parent
51e662fdda
commit
1409d4ef80
@ -24,6 +24,7 @@ public:
|
|||||||
void AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line);
|
void AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line);
|
||||||
// cleared when Logged
|
// cleared when Logged
|
||||||
void SetTransaction(const std::string& id);
|
void SetTransaction(const std::string& id);
|
||||||
|
[[nodiscard]] std::unique_lock<std::mutex> CreateExclusiveContext();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mValid { true };
|
bool mValid { true };
|
||||||
|
@ -48,6 +48,7 @@ void THeartbeatThread::operator()() {
|
|||||||
debug("server returned \"" + T + "\"");
|
debug("server returned \"" + T + "\"");
|
||||||
if (T.size() > std::string("YOU_SHALL_NOT_PASS").size()
|
if (T.size() > std::string("YOU_SHALL_NOT_PASS").size()
|
||||||
&& Application::Settings.Key.size() == 36) {
|
&& Application::Settings.Key.size() == 36) {
|
||||||
|
auto Lock = Sentry.CreateExclusiveContext();
|
||||||
Sentry.AddExtra("response-body", T);
|
Sentry.AddExtra("response-body", T);
|
||||||
Sentry.AddExtra("request-body", Body);
|
Sentry.AddExtra("request-body", Body);
|
||||||
Sentry.SetTransaction(Application::GetBackendHostname() + Target);
|
Sentry.SetTransaction(Application::GetBackendHostname() + Target);
|
||||||
|
@ -297,6 +297,7 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
|||||||
if (!AuthResponse.IsObject() && Rc != "0") {
|
if (!AuthResponse.IsObject() && Rc != "0") {
|
||||||
ClientKick(*Client, "Backend returned invalid auth response format.");
|
ClientKick(*Client, "Backend returned invalid auth response format.");
|
||||||
error("Backend returned invalid auth response format. This should never happen.");
|
error("Backend returned invalid auth response format. This should never happen.");
|
||||||
|
auto Lock = Sentry.CreateExclusiveContext();
|
||||||
Sentry.AddExtra("response-body", Rc);
|
Sentry.AddExtra("response-body", Rc);
|
||||||
Sentry.AddExtra("key", RequestString);
|
Sentry.AddExtra("key", RequestString);
|
||||||
Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target);
|
Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target);
|
||||||
|
@ -47,7 +47,7 @@ void TSentry::Log(sentry_level_t level, const std::string& logger, const std::st
|
|||||||
|
|
||||||
void TSentry::LogDebug(const std::string& text, const std::string& file, const std::string& line) {
|
void TSentry::LogDebug(const std::string& text, const std::string& file, const std::string& line) {
|
||||||
SetTransaction(file + ":" + line);
|
SetTransaction(file + ":" + line);
|
||||||
Log(SENTRY_LEVEL_DEBUG, "default", file + ": " + text);
|
Log(SENTRY_LEVEL_DEBUG, "default", file + ": " + text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSentry::AddExtra(const std::string& key, const sentry_value_t& value) {
|
void TSentry::AddExtra(const std::string& key, const sentry_value_t& value) {
|
||||||
@ -86,3 +86,7 @@ void TSentry::SetTransaction(const std::string& id) {
|
|||||||
}
|
}
|
||||||
sentry_set_transaction(id.c_str());
|
sentry_set_transaction(id.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> TSentry::CreateExclusiveContext() {
|
||||||
|
return std::unique_lock<std::mutex>(mMutex);
|
||||||
|
}
|
||||||
|
@ -323,6 +323,7 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
|||||||
std::string VD = c.GetCarData(VID);
|
std::string VD = c.GetCarData(VID);
|
||||||
if (VD.empty()) {
|
if (VD.empty()) {
|
||||||
error("Tried to apply change to vehicle that does not exist");
|
error("Tried to apply change to vehicle that does not exist");
|
||||||
|
auto Lock = Sentry.CreateExclusiveContext();
|
||||||
Sentry.AddExtra("packet", Packet);
|
Sentry.AddExtra("packet", Packet);
|
||||||
Sentry.AddExtra("vehicle-id", std::to_string(VID));
|
Sentry.AddExtra("vehicle-id", std::to_string(VID));
|
||||||
Sentry.AddExtra("client-car-count", std::to_string(c.GetCarCount()));
|
Sentry.AddExtra("client-car-count", std::to_string(c.GetCarCount()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user