Skip to content

Commit 20631c5

Browse files
authored
Merge pull request #3070 from qhyou11/follow-the-upstream
Fixed the memory leak problem
2 parents 4843f12 + 792da0e commit 20631c5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

api/debug/gc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package debug
33
import (
44
"net/http"
55
"runtime"
6+
7+
"github.com/gorilla/context"
68
)
79

810
func GC(w http.ResponseWriter, r *http.Request) {
11+
context.Purge(600)
912
runtime.GC()
1013
w.WriteHeader(http.StatusNoContent)
1114
}

api/projects/tasks.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7+
"net/http"
8+
"strconv"
9+
"time"
10+
711
"github.com/gorilla/context"
812
"github.com/semaphoreui/semaphore/api/helpers"
913
"github.com/semaphoreui/semaphore/db"
1014
"github.com/semaphoreui/semaphore/services/tasks"
1115
"github.com/semaphoreui/semaphore/util"
1216
log "github.com/sirupsen/logrus"
13-
"net/http"
14-
"strconv"
15-
"time"
1617
)
1718

1819
// AddTask inserts a task into the database and returns a header or returns error
@@ -103,6 +104,7 @@ func GetTask(w http.ResponseWriter, r *http.Request) {
103104
// GetTaskMiddleware is middleware that gets a task by id and sets the context to it or panics
104105
func GetTaskMiddleware(next http.Handler) http.Handler {
105106
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
107+
defer context.Clear(r)
106108
project := context.Get(r, "project").(db.Project)
107109
taskID, err := helpers.GetIntParam("task_id", w, r)
108110

0 commit comments

Comments
 (0)