Skip to content

Commit b4e2960

Browse files
committed
issue #75: fix crash when retrieving cache info
It seems there are chances in which :mnesia.table_info can return :undefined for :size and :memory entries. This might be happening when Mnesia table is not yet fully loaded. Signed-off-by: Matteo Cafasso <[email protected]>
1 parent 9608636 commit b4e2960

File tree

1 file changed

+11
-8
lines changed
  • lib/rabbitmq_message_deduplication

1 file changed

+11
-8
lines changed

lib/rabbitmq_message_deduplication/cache.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,17 @@ defmodule RabbitMQMessageDeduplication.Cache do
128128
"""
129129
@spec info(atom) :: list
130130
def info(cache) do
131-
info = [
132-
bytes: Mnesia.table_info(cache, :memory) * Erlang.system_info(:wordsize),
133-
entries: Mnesia.table_info(cache, :size)
134-
]
135-
136-
case cache_property(cache, :limit) do
137-
number when is_integer(number) -> [size: number] ++ info
138-
nil -> info
131+
with entries when is_integer(entries) <- Mnesia.table_info(cache, :size),
132+
words when is_integer(words) <- Mnesia.table_info(cache, :memory)
133+
do
134+
bytes = words * Erlang.system_info(:wordsize)
135+
136+
case cache_property(cache, :limit) do
137+
nil -> [entries: entries, bytes: bytes]
138+
size -> [entries: entries, bytes: bytes, size: size]
139+
end
140+
else
141+
:undefined -> []
139142
end
140143
end
141144

0 commit comments

Comments
 (0)