Skip to content

Commit

Permalink
possible cause of observed deadlock: removed possibility of communica…
Browse files Browse the repository at this point in the history
…ting over the idle_workers channel with a lock and ending up in closenotify case causing a deadlock
  • Loading branch information
realtux committed Apr 21, 2017
1 parent d49db64 commit c94551f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/dispenserd/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func InsertJob(job job) {
}

if idle_workers[lane] > 0 {
mu.Unlock()
listeners[lane] <- 1
} else {
mu.Unlock()
Expand Down
13 changes: 10 additions & 3 deletions src/dispenserd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

var listeners = map[string]chan int{"main": make(chan int)}
var ready = make(chan int)

type generic_payload struct {
Status string `json:"status"`
Expand Down Expand Up @@ -209,16 +208,24 @@ func ServiceReceiveBlock(res http.ResponseWriter, req *http.Request) {
for {
select {
case <-listeners[current_lane]:
if len(queue[current_lane]) == 0 {
mu.Lock()

// empty queue or no workers means do nothing
if len(queue[current_lane]) == 0 || idle_workers[current_lane] == 0 {
mu.Unlock()
continue
}

idle_workers[current_lane] -= 1

send_job()

return
case <-cn.CloseNotify():
mu.Lock()
idle_workers[current_lane] -= 1
if idle_workers[current_lane] > 0 {
idle_workers[current_lane] -= 1
}
mu.Unlock()

return
Expand Down

0 comments on commit c94551f

Please sign in to comment.