|
57 | 57 | (str "`aleph.resource_leak_detector` requires `-Dio.netty.leakDetection.level=PARANOID`. "
|
58 | 58 | "Current level is `" (ResourceLeakDetector/getLevel) "`.")))))
|
59 | 59 |
|
60 |
| -(def +max-probe-gc-runs+ |
| 60 | +(def max-probe-gc-runs |
61 | 61 | "Maximum number of times the GC will be run to detect a leaked probe."
|
62 | 62 | 10)
|
63 | 63 |
|
64 |
| -(def +probe-hint-marker+ |
| 64 | +(def probe-hint-marker |
65 | 65 | "ALEPH LEAK DETECTOR PROBE")
|
66 | 66 |
|
67 | 67 | (defn hint-record-pattern [hint-pattern]
|
68 | 68 | (re-pattern (str "(?m)^\\s*Hint: " hint-pattern "$")))
|
69 | 69 |
|
70 |
| -(def +probe-hint-pattern+ |
71 |
| - (hint-record-pattern (str +probe-hint-marker+ " \\d+"))) |
| 70 | +(def probe-hint-pattern |
| 71 | + (hint-record-pattern (str probe-hint-marker " \\d+"))) |
72 | 72 |
|
73 | 73 | (defn probe? [leak]
|
74 |
| - (re-find +probe-hint-pattern+ (:records leak))) |
| 74 | + (re-find probe-hint-pattern (:records leak))) |
75 | 75 |
|
76 | 76 | (defn contains-hint? [hint leak]
|
77 | 77 | (re-find (hint-record-pattern hint) (:records leak)))
|
|
81 | 81 |
|
82 | 82 | (let [cnt (atom 0)]
|
83 | 83 | (defn gen-probe-hint []
|
84 |
| - (str +probe-hint-marker+ " " (swap! cnt inc)))) |
| 84 | + (str probe-hint-marker " " (swap! cnt inc)))) |
85 | 85 |
|
86 | 86 | (defn leak-probe! [hint]
|
87 | 87 | (-> AbstractByteBufAllocator/DEFAULT
|
|
98 | 98 | (-> AbstractByteBufAllocator/DEFAULT (.buffer 1) .release))
|
99 | 99 |
|
100 | 100 | (defn await-probe! [probe-hint]
|
101 |
| - (loop [n +max-probe-gc-runs+] |
| 101 | + (loop [n max-probe-gc-runs] |
102 | 102 | (force-leak-detection!)
|
103 | 103 | (if (zero? n)
|
104 |
| - (throw (RuntimeException. "Gave up awaiting leak probe. Try increasing +max-probe-gc-runs+.")) |
| 104 | + (throw (RuntimeException. "Gave up awaiting leak probe. Try increasing `aleph.resource-leak-detector/max-probe-gc-runs`.")) |
105 | 105 | (when-not (some (partial contains-hint? probe-hint) @current-leaks)
|
106 | 106 | (recur (dec n))))))
|
107 | 107 |
|
|
0 commit comments