Guard HTTP build job chan with a mutex
to ensure serial access so that only one build job chan is created.
@@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"strconv"
+ "sync"
"time"
"github.com/bitly/go-simplejson"
@@ -27,6 +28,7 @@ type HTTPJobQueue struct {
queue string
workerID string
buildJobChan chan Job
+ buildJobChanMutex *sync.Mutex
DefaultLanguage, DefaultDist, DefaultGroup, DefaultOS string
}
@@ -54,11 +56,14 @@ func NewHTTPJobQueue(pool *ProcessorPool, jobBoardURL *url.URL, site, providerNa
providerName: providerName,
queue: queue,
workerID: workerID,
+ buildJobChanMutex: &sync.Mutex{},
}, nil
}
// Jobs consumes new jobs from job-board
func (q *HTTPJobQueue) Jobs(ctx gocontext.Context) (outChan <-chan Job, err error) {
+ q.buildJobChanMutex.Lock()
+ defer q.buildJobChanMutex.Unlock()
logger := context.LoggerFromContext(ctx)
if q.buildJobChan != nil {
return q.buildJobChan, nil
