Skip to content

Commit

Permalink
fix memory leaks in multimethod default dispatch caches
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Dec 12, 2023
1 parent 0ef9046 commit d86ac6a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 17 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: Run tests

on:
push:
branches: [master]
pull_request:
branches: [master]

env:
ACTIONS_CACHE_VERSION: 0

jobs:
test:
strategy:
matrix:
jdk: [8, 11, 17, 21]

name: Java ${{ matrix.jdk }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Java ${{ matrix.jdk }}
uses: actions/[email protected]
with:
distribution: temurin
java-version: ${{ matrix.jdk }}
- name: Maven Cache
id: maven-cache
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.gitlibs
key: m2-cache-${{ env.ACTIONS_CACHE_VERSION }}-${{ hashFiles('project.clj') }}-${{ matrix.jdk }}
restore-keys: |
m2-cache-${{ env.ACTIONS_CACHE_VERSION }}-${{ hashFiles('project.clj') }}-
m2-cache-${{ env.ACTIONS_CACHE_VERSION }}-
- name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master
with:
lein: latest
- name: Run tests
run: lein do clean, all midje, all check
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Fix memory leaks via multimethods caching default dispatch values: https://github.com/metosin/compojure-api/issues/454

## 0.26.2 (1.4.2019)

* `s/eq` is mapped into enum by [Joel Kaasinen](https://github.com/opqdonut).
Expand Down
7 changes: 5 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
[metosin/ring-swagger-ui "3.20.1"]
[javax.servlet/javax.servlet-api "4.0.1"]]}
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.1"]]}
:1.11 {:dependencies [[org.clojure/clojure "1.11.1"]]}
:1.12 {:dependencies [[org.clojure/clojure "1.12.0-alpha5"]]}}
:codeina {:sources ["src"]
:target "gh-pages/doc"
:src-uri "https://github.com/metosin/ring-swagger/blob/master/"
:src-uri-prefix "#L"}
:deploy-repositories [["releases" :clojars]]
:aliases {"all" ["with-profile" "dev:dev,1.7:dev,1.9"]
:aliases {"all" ["with-profile" "dev:dev,1.7:dev,1.9:dev,1.10:dev,1.11:dev,1.12"]
"test-ancient" ["midje"]})
12 changes: 9 additions & 3 deletions src/ring/swagger/coerce.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

(declare custom-matcher)

(defmulti time-matcher identity)
(defmulti time-matcher (if (= "true" (System/getProperty "ring.swagger.coerce.identity-time-matcher-dispatch"))
identity
#(when (class? %) %)))

(defn coerce-if-string [f] (fn [x] (if (string? x) (f x) x)))

Expand Down Expand Up @@ -175,10 +177,14 @@
;; Public Api
;;

(defmulti custom-matcher identity)
(defmulti custom-matcher (if (= "true" (System/getProperty "ring.swagger.coerce.identity-custom-matcher-dispatch"))
identity
#(when (class? %) %)))
(defmethod custom-matcher :default [_] nil)

(defmulti coercer identity)
(defmulti coercer (if (= "true" (System/getProperty "ring.swagger.coerce.identity-coercer-dispatch"))
identity
#(when (keyword? %) %)))

(defmethod coercer :json [_] json-schema-coercion-matcher)
(defmethod coercer :query [_] query-schema-coercion-matcher)
Expand Down
6 changes: 4 additions & 2 deletions test/ring/swagger/extension_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
(fact "undefined vars/classes are ignored in disabled extensions"
(resolve 'a) => nil
(disabled (a)) =not=> (throws Exception)
(resolve 'dummy.Class) => (throws ClassNotFoundException)
(try (resolve 'dummy.Class)
(catch ClassNotFoundException _)) => nil
(disabled (dummy.Class)) =not=> (throws Exception)))

(fact "java-time extension"
Expand All @@ -34,4 +35,5 @@
(extension/java-time :a) => :a)
(fact "skips the enclosed form"
(extension/java-time :a) => nil
(resolve 'java.time.Instant) => (throws ClassNotFoundException)))))
(try (resolve 'java.time.Instant)
(catch ClassNotFoundException _)) => nil))))

0 comments on commit d86ac6a

Please sign in to comment.