Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 769e141

Browse files
committed
Warn if inserting to a wheel timer that hasn't been read recently
1 parent bae9665 commit 769e141

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

synapse/util/wheel_timer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import logging
1415
from typing import Generic, Hashable, List, Set, TypeVar
1516

17+
logger = logging.getLogger(__name__)
18+
1619
T = TypeVar("T", bound=Hashable)
1720

1821

@@ -51,17 +54,27 @@ def insert(self, now: int, obj: T, then: int) -> None:
5154
then: When to return the object strictly after.
5255
"""
5356
then_key = int(then / self.bucket_size) + 1
57+
now_key = int(now / self.bucket_size)
5458

5559
if self.entries:
5660
min_key = self.entries[0].end_key
5761
max_key = self.entries[-1].end_key
5862

63+
if min_key < now_key - 10:
64+
# If we have ten buckets that are due and still nothing has
65+
# called `fetch()` then we likely have a bug that is causing a
66+
# memory leak.
67+
logger.warning(
68+
"Inserting into a wheel timer that hasn't been read from recently. Item: %s",
69+
obj,
70+
)
71+
5972
if then_key <= max_key:
6073
# The max here is to protect against inserts for times in the past
6174
self.entries[max(min_key, then_key) - min_key].queue.add(obj)
6275
return
6376

64-
next_key = int(now / self.bucket_size) + 1
77+
next_key = now_key + 1
6578
if self.entries:
6679
last_key = self.entries[-1].end_key
6780
else:

0 commit comments

Comments
 (0)