Skip to content

Commit ec43c89

Browse files
authored
Merge pull request #647 from ohsu-comp-bio/close-files
FIX: Open File leak
2 parents b906ba8 + e7bd3f1 commit ec43c89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+181
-35
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ start-mongodb:
9999
@docker run -d --name funnel-mongodb-test -p 27000:27017 docker.io/mongo:3.5.13 > /dev/null
100100

101101
test-mongodb:
102-
@go test ./tests/core/ -funnel-config `pwd`/tests/mongo.config.yml
103-
@go test ./tests/scheduler/ -funnel-config `pwd`/tests/mongo.config.yml
102+
@go test ./tests/core/ --funnel-config `pwd`/tests/mongo.config.yml
103+
@go test ./tests/scheduler/ --funnel-config `pwd`/tests/mongo.config.yml
104104

105105
test-badger:
106106
@go test ./tests/core/ -funnel-config `pwd`/tests/badger.config.yml

cmd/server/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type Server struct {
4747
// Database represents the base funnel database interface
4848
type Database interface {
4949
tes.ReadOnlyServer
50-
events.Writer
5150
Init() error
5251
}
5352

cmd/worker/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func newDatabaseTaskReader(taskID string, db tes.ReadOnlyServer, err error) (wor
123123
if err != nil {
124124
return nil, fmt.Errorf("creating database task reader: %v", err)
125125
}
126-
return worker.NewGenericTaskReader(db.GetTask, taskID), nil
126+
return worker.NewGenericTaskReader(db.GetTask, taskID, db.Close), nil
127127
}
128128

129129
// eventWriterBuilder is a helper for building a set of event writers,

compute/batch/backend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (b *Backend) WriteEvent(ctx context.Context, ev *events.Event) error {
6262
return nil
6363
}
6464

65+
func (b *Backend) Close() {
66+
b.database.Close()
67+
b.event.Close()
68+
}
69+
6570
// Submit submits a task to the AWS batch service.
6671
func (b *Backend) Submit(task *tes.Task) error {
6772
ctx := context.Background()

compute/hpc_backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func (b *HPCBackend) WriteEvent(ctx context.Context, ev *events.Event) error {
5555
return nil
5656
}
5757

58+
func (b *HPCBackend) Close() {}
59+
5860
// Submit submits a task via "qsub", "condor_submit", "sbatch", etc.
5961
func (b *HPCBackend) Submit(task *tes.Task) error {
6062
ctx := context.Background()

compute/kubernetes/backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func (b *Backend) WriteEvent(ctx context.Context, ev *events.Event) error {
105105
return nil
106106
}
107107

108+
func (b *Backend) Close() {
109+
//TODO: close database?
110+
}
111+
108112
// createJob uses the configured template to create a kubernetes batch job.
109113
func (b *Backend) createJob(task *tes.Task) (*v1.Job, error) {
110114
submitTpl, err := template.New(task.Id).Parse(b.template)

compute/local/backend.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func (b *Backend) WriteEvent(ctx context.Context, ev *events.Event) error {
3232
return nil
3333
}
3434

35+
func (b *Backend) Close() {}
36+
3537
// Submit submits a task. For the Local backend this results in the task
3638
// running immediately.
3739
func (b *Backend) Submit(task *tes.Task) error {
@@ -46,6 +48,7 @@ func (b *Backend) Submit(task *tes.Task) error {
4648

4749
go func() {
4850
w.Run(ctx)
51+
w.Close()
4952
}()
5053
return nil
5154
}

compute/noop/backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ type Backend struct{}
2020
func (b *Backend) WriteEvent(context.Context, *events.Event) error {
2121
return nil
2222
}
23+
24+
func (b *Backend) Close() {}

database/badger/new.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (db *Badger) Init() error {
3232
return nil
3333
}
3434

35+
func (db *Badger) Close() {
36+
db.db.Close()
37+
}
38+
3539
var taskKeyPrefix = []byte("tasks")
3640

3741
func taskKey(id string) []byte {

database/boltdb/new.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ func (taskBolt *BoltDB) Init() error {
9595
return nil
9696
})
9797
}
98+
99+
func (taskBolt *BoltDB) Close() {
100+
taskBolt.db.Close()
101+
}

0 commit comments

Comments
 (0)