Skip to content

Commit

Permalink
Merge pull request #1 from threatgrid/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
frenchy64 authored Aug 11, 2023
2 parents 0ef9046 + 5a563d2 commit 3f15dad
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 20 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: Run tests

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

env:
ACTIONS_CACHE_VERSION: 0

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

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
deploy:
concurrency: deploy
needs: test
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/project.clj') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Prepare java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'
- name: deploy
env:
CLOJARS_USER: 'threatgrid-clojars'
CLOJARS_TOKEN: ${{ secrets.CLOJARS_TOKEN }}
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Threatgrid"
if [[ "$COMMIT_MSG" == "Release :major" ]]; then
lein release :major
elif [[ "$COMMIT_MSG" == "Release :minor" ]]; then
lein release :minor
elif [[ "$COMMIT_MSG" == "Release :patch" ]]; then
lein release :patch
else
lein deploy snapshot
fi
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 @@
## [threatgrid] 0.26.3 (?)

* Fix memory leaks via multimethods caching default dispatch values

## 0.26.2 (1.4.2019)

* `s/eq` is mapped into enum by [Joel Kaasinen](https://github.com/opqdonut).
Expand Down
13 changes: 8 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metosin/ring-swagger "0.26.2"
(defproject io.github.threatgrid/ring-swagger "0.26.3-SNAPSHOT"
:description "Swagger Spec for Ring Apps"
:url "https://github.com/metosin/ring-swagger"
:license {:name "Eclipse Public License"
Expand All @@ -20,18 +20,21 @@
[lein-ring "0.12.5"]
[lein-midje "3.2.1"]
[funcool/codeina "0.5.0"]]
:dependencies [[org.clojure/clojure "1.8.0"]
:dependencies [[org.clojure/clojure "1.11.1"]
[midje "1.9.6" :exclusions [org.clojure/clojure
commons-codec]]
[ring-mock "0.1.5"]
[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.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.1"]]}
:1.12 {:dependencies [[org.clojure/clojure "1.12.0-alpha4"]]}}
:codeina {:sources ["src"]
:target "gh-pages/doc"
:src-uri "http://github.com/metosin/ring-swagger/blob/master/"
:src-uri "https://github.com/threatgrid/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.8:dev,1.9:dev,1.10: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 3f15dad

Please sign in to comment.