summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorJ. Ryan Stinnett <jryans@gmail.com>2019-09-18 18:00:49 +0100
committerJ. Ryan Stinnett <jryans@gmail.com>2019-09-18 18:03:22 +0100
commit5d4d1ad77e8016817ca3ded58d9b2cc41cb55f4d (patch)
tree2c03b215d95a88370726ca33fbf939d3a0de9051 /synapse
parentMerge pull request #6004 from matrix-org/jaywink/autojoin-create-real-users (diff)
downloadsynapse-5d4d1ad77e8016817ca3ded58d9b2cc41cb55f4d.tar.xz
Fix logcontext spam on non-Linux platforms
This checks whether the current platform supports thread resource usage tracking
before logging a warning to avoid log spam.

Fixes https://github.com/matrix-org/synapse/issues/6055
Diffstat (limited to 'synapse')
-rw-r--r--synapse/logging/context.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/synapse/logging/context.py b/synapse/logging/context.py
index 63379bfb93..4bca44d4e1 100644
--- a/synapse/logging/context.py
+++ b/synapse/logging/context.py
@@ -1,4 +1,5 @@
 # Copyright 2014-2016 OpenMarket Ltd
+# Copyright 2019 The Matrix.org Foundation C.I.C.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -42,13 +43,19 @@ try:
     # exception.
     resource.getrusage(RUSAGE_THREAD)
 
+    def is_thread_resource_usage_supported():
+        return True
+
     def get_thread_resource_usage():
         return resource.getrusage(RUSAGE_THREAD)
 
 
 except Exception:
     # If the system doesn't support resource.getrusage(RUSAGE_THREAD) then we
-    # won't track resource usage by returning None.
+    # won't track resource usage.
+    def is_thread_resource_usage_supported():
+        return False
+
     def get_thread_resource_usage():
         return None
 
@@ -359,7 +366,9 @@ class LoggingContext(object):
 
         # When we stop, let's record the cpu used since we started
         if not self.usage_start:
-            logger.warning("Called stop on logcontext %s without calling start", self)
+            # Log a warning on platforms that support thread usage tracking
+            if is_thread_resource_usage_supported():
+                logger.warning("Called stop on logcontext %s without calling start", self)
             return
 
         utime_delta, stime_delta = self._get_cputime()