Skip to content

Commit

Permalink
- Fixing the leakage of process when the TKTWorker is GCed.
Browse files Browse the repository at this point in the history
- Fixing the tests and improving.
- Improving the rest of the watchdog.
  • Loading branch information
tesonep committed Jul 2, 2020
1 parent 2fb9d24 commit 265d967
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion TaskIt-Tests/TKTCommonQueueWorkerPoolTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TKTCommonQueueWorkerPoolTest >> testWorkerPoolDoesNotExceedPoolSizeWhenSchedulin
1 to: 10 do: [ :i | futures nextPut: (pool future: [ 10 timesRepeat: [ futures nextPut: (pool future: [ totalTasks := totalTasks + 1 ]) ] ]) ].
[ futures isEmpty ] whileFalse: [ futures next waitForCompletion: 100 milliSeconds ].
self assert: totalTasks equals: 100.
self assert: pool size equals: 10
self assert: pool size <= 10
]

{ #category : #tests }
Expand Down
2 changes: 1 addition & 1 deletion TaskIt-Tests/TKTMemoryLeakTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ TKTMemoryLeakTest >> trackInstancesOf: aClass during: aBlock [

self garbageCollectAndWait .

self assert: before equals: aClass allInstances size.
self assert: before >= aClass allInstances size.
]
7 changes: 7 additions & 0 deletions TaskIt/TKTConfiguration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ TKTConfiguration class >> profiles [
^ TKTProfile profiles
]

{ #category : #accessing }
TKTConfiguration class >> resetSoleInstance [

TKTWatchDog reset.
super resetSoleInstance.
]

{ #category : #accessing }
TKTConfiguration class >> runner [
^ self optionAt: #runner
Expand Down
12 changes: 12 additions & 0 deletions TaskIt/TKTWatchDog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ TKTWatchDog class >> onDuty [
onDuty ]
]

{ #category : #reseting }
TKTWatchDog class >> reset [

onDuty ifNotNil: [ onDuty stop ].
onDuty := nil.
]

{ #category : #initialization }
TKTWatchDog >> cleanUpImageToStart [
values removeAll
Expand Down Expand Up @@ -60,6 +67,11 @@ TKTWatchDog >> name [
^ 'WatchDog (' , id asString , ')'
]

{ #category : #'as yet unclassified' }
TKTWatchDog >> pharoProcess [
^ worker process process
]

{ #category : #initialization }
TKTWatchDog >> privateStart [
stopRequested := false.
Expand Down
16 changes: 8 additions & 8 deletions TaskIt/TKTWorker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ TKTWorker >> exceptionHandler: aHandler [
]

{ #category : #finalization }
TKTWorker >> finalize [
TKTConfiguration watchDog stopWatching: self.
self
schedule: [ | theProcess |
queue := nil.
theProcess := process.
theProcess ifNotNil: [ theProcess kill ].
process := nil ].
TKTWorker >> executor [

"The finalization scheme runs in another object (the executor) that does not have
all the state, if it has all the state a loop is generated and never GCed"

^ TKTWorkerExecutor new
processToKill: process;
yourself.
]

{ #category : #initialization }
Expand Down
23 changes: 23 additions & 0 deletions TaskIt/TKTWorkerExecutor.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"
I am an object that will be used as executor of the TKTWorker.
In that way I don't need to copy the TKTWorker and nilling its instance variables.
"
Class {
#name : #TKTWorkerExecutor,
#superclass : #Object,
#instVars : [
'processToKill'
],
#category : #'TaskIt-Worker'
}

{ #category : #finalization }
TKTWorkerExecutor >> finalize [

(processToKill at: 1) ifNotNil: [:e | e kill]
]

{ #category : #accessing }
TKTWorkerExecutor >> processToKill: anObject [
processToKill := WeakArray with: anObject
]

0 comments on commit 265d967

Please sign in to comment.