Skip to content

Commit 574ce21

Browse files
committed
Spider - fix zombied job bug
Commit 0982873 introduced a bug which made it possible to have zombied jobs still running within the GUI despite pressing the stop button. One of the callbacks must block and therefore stop the other callbacks being completed. As this code has worked for a long time, it feels better to simply revert to it rather than to start digging further to attempt to find and resolve the core issue - especially as all this stuff will likely be significantly reworked in the future. Also fix other (related) issues by doing a little more checking.
1 parent 2b99fe4 commit 574ce21

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

app/server/ruby/lib/sonicpi/jobs.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def kill_job(id)
3737
@mut.synchronize do
3838
job = @jobs.delete(id)
3939
if job
40-
__system_thread_locals(job[:job]).get(:sonic_pi_local_spider_no_kill_mutex).synchronize do
40+
mut =__system_thread_locals(job[:job]).get(:sonic_pi_local_spider_no_kill_mutex)
41+
if mut
42+
mut.synchronize do
43+
job[:job].kill
44+
end
45+
else
4146
job[:job].kill
4247
end
4348
end

app/server/ruby/lib/sonicpi/lifecyclehooks.rb

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,45 +73,35 @@ def on_all_completed(&blck)
7373

7474
def init(job_id, arg={})
7575
log "Lifecycle Hooks Init"
76-
@mut.synchronize do
77-
@started = true
78-
@started_blocks.each do |b|
79-
b.call(job_id, arg)
80-
end
76+
@started = true
77+
@started_blocks.each do |b|
78+
b.call(job_id, arg)
8179
end
8280
end
8381

8482
def completed(job_id, arg={})
8583
log "Lifecycle Hooks Completed"
86-
@mut.synchronize do
87-
@completed_blocks.each do |b|
88-
b.call(job_id, arg)
89-
end
84+
@completed_blocks.each do |b|
85+
b.call(job_id, arg)
9086
end
9187
end
9288

9389
def all_completed(silent=false)
9490
log "Lifecycle Hooks All Completed"
95-
@mut.synchronize do
96-
@all_completed_blocks.each do |b|
97-
b.call(silent)
98-
end
91+
@all_completed_blocks.each do |b|
92+
b.call(silent)
9993
end
10094
end
10195

10296
def killed(job_id, arg={})
103-
@mut.synchronize do
104-
@killed_blocks.each do |b|
105-
b.call(job_id, arg)
106-
end
97+
@killed_blocks.each do |b|
98+
b.call(job_id, arg)
10799
end
108100
end
109101

110102
def exit(job_id, arg={})
111-
@mut.synchronize do
112-
@exited_blocks.each do |b|
113-
b.call(job_id, arg)
114-
end
103+
@exited_blocks.each do |b|
104+
b.call(job_id, arg)
115105
end
116106
end
117107
end

app/server/ruby/lib/sonicpi/runtime.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ def __set_default_user_thread_locals!
850850
end
851851

852852
def __spider_eval(code, info={})
853+
now = Time.now.freeze
853854
# skip __nosave lines for error reporting
854855
firstline = 1
855856
firstline -= code.lines.to_a.take_while{|l| l.include? "#__nosave__"}.count
@@ -878,8 +879,7 @@ def __spider_eval(code, info={})
878879
__set_default_user_thread_locals!
879880
__msg_queue.push({type: :job, jobid: id, action: :start, jobinfo: info})
880881
@life_hooks.init(id, {:thread => Thread.current})
881-
now = Time.now.freeze
882-
start_t_prom.deliver! now
882+
883883
## fix this for link
884884
__reset_spider_time_and_beat!
885885
if num_running_jobs == 1
@@ -893,6 +893,8 @@ def __spider_eval(code, info={})
893893
job_in_thread = in_thread seed: 0 do
894894
eval(code, nil, info[:workspace], firstline)
895895
end
896+
897+
start_t_prom.deliver! now
896898
__schedule_delayed_blocks_and_messages!
897899
rescue Stop => e
898900
__no_kill_block do
@@ -937,7 +939,7 @@ def __spider_eval(code, info={})
937939
Thread.current.priority = -10
938940
__system_thread_locals.set_local(:sonic_pi_local_thread_group, "job-#{id}-GC")
939941
job.join
940-
__system_thread_locals(job_in_thread).get(:sonic_pi_local_spider_subthread_empty).get
942+
__system_thread_locals(job_in_thread).get(:sonic_pi_local_spider_subthread_empty).get if job_in_thread
941943

942944
# wait until all synths are dead
943945
@life_hooks.completed(id)

0 commit comments

Comments
 (0)