Archived
1
0

try fixing deadlock

This commit is contained in:
Jeff Becker 2017-09-26 09:50:14 -04:00
parent 73cf6da65d
commit 3ee449062e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
4 changed files with 40 additions and 59 deletions

View File

@ -874,7 +874,7 @@ func (self *NNTPDaemon) poll(worker int) {
// send to frontend // send to frontend
if self.frontend != nil { if self.frontend != nil {
if self.frontend.AllowNewsgroup(group) { if self.frontend.AllowNewsgroup(group) {
self.frontend.PostsChan() <- frontendPost{msgid, ref, group} self.frontend.HandleNewPost(frontendPost{msgid, ref, group})
} }
} }
} }

View File

@ -25,8 +25,8 @@ func (p frontendPost) Newsgroup() string {
// frontend interface for any type of frontend // frontend interface for any type of frontend
type Frontend interface { type Frontend interface {
// channel that is for the frontend to pool for new posts from the nntpd // handle new post from nntpd
PostsChan() chan frontendPost HandleNewPost(p frontendPost)
// run mainloop // run mainloop
Mainloop() Mainloop()
@ -36,6 +36,7 @@ type Frontend interface {
// trigger a manual regen of indexes for a root post // trigger a manual regen of indexes for a root post
Regen(msg ArticleEntry) Regen(msg ArticleEntry)
// regenerate on mod event // regenerate on mod event
RegenOnModEvent(newsgroup, msgid, root string, page int) RegenOnModEvent(newsgroup, msgid, root string, page int)
} }

View File

@ -175,7 +175,6 @@ type httpFrontend struct {
httpmux *mux.Router httpmux *mux.Router
daemon *NNTPDaemon daemon *NNTPDaemon
cache CacheInterface cache CacheInterface
recvpostchan chan frontendPost
bindaddr string bindaddr string
name string name string
@ -222,10 +221,6 @@ func (self httpFrontend) AllowNewsgroup(group string) bool {
return newsgroupValidFormat(group) || group == "ctl" && !strings.HasSuffix(group, ".") return newsgroupValidFormat(group) || group == "ctl" && !strings.HasSuffix(group, ".")
} }
func (self httpFrontend) PostsChan() chan frontendPost {
return self.recvpostchan
}
func (self *httpFrontend) Regen(msg ArticleEntry) { func (self *httpFrontend) Regen(msg ArticleEntry) {
self.cache.Regen(msg) self.cache.Regen(msg)
} }
@ -406,12 +401,14 @@ func (self *httpFrontend) poll() {
} else { } else {
log.Println("failed to register mod message, file was not opened") log.Println("failed to register mod message, file was not opened")
} }
case nntp := <-self.recvpostchan: }
// get root post and tell frontend to regen that thread }
}
func (self *httpFrontend) HandleNewPost(nntp frontendPost) {
msgid := nntp.MessageID() msgid := nntp.MessageID()
group := nntp.Newsgroup() group := nntp.Newsgroup()
ref := nntp.Reference() ref := nntp.Reference()
self.informLiveUI(msgid, ref, group) go self.informLiveUI(msgid, ref, group)
if len(ref) > 0 { if len(ref) > 0 {
msgid = ref msgid = ref
} }
@ -430,8 +427,6 @@ func (self *httpFrontend) poll() {
} }
self.regenGroupChan <- req self.regenGroupChan <- req
} }
}
}
} }
// create a new captcha, return as json object // create a new captcha, return as json object
@ -1569,7 +1564,7 @@ func NewHTTPFrontend(daemon *NNTPDaemon, cache CacheInterface, config map[string
Path: front.prefix, Path: front.prefix,
MaxAge: 600, MaxAge: 600,
} }
front.recvpostchan = make(chan frontendPost)
front.regenThreadChan = front.cache.GetThreadChan() front.regenThreadChan = front.cache.GetThreadChan()
front.regenGroupChan = front.cache.GetGroupChan() front.regenGroupChan = front.cache.GetGroupChan()

View File

@ -7,7 +7,6 @@ package srnd
// muxed frontend for holding many frontends // muxed frontend for holding many frontends
type multiFrontend struct { type multiFrontend struct {
muxedpostchan chan frontendPost
frontends []Frontend frontends []Frontend
} }
@ -25,25 +24,12 @@ func (self multiFrontend) Mainloop() {
for idx := range self.frontends { for idx := range self.frontends {
go self.frontends[idx].Mainloop() go self.frontends[idx].Mainloop()
} }
// poll for incoming
chnl := self.PostsChan()
for {
select {
case nntp := <-chnl:
for _, frontend := range self.frontends {
if frontend.AllowNewsgroup(nntp.Newsgroup()) {
ch := frontend.PostsChan()
ch <- nntp
}
}
break
}
}
} }
func (self multiFrontend) PostsChan() chan frontendPost { func (self multiFrontend) HandleNewPost(nntp frontendPost) {
return self.muxedpostchan for idx := range self.frontends {
self.frontends[idx].HandleNewPost(nntp)
}
} }
func (self multiFrontend) RegenOnModEvent(newsgroup, msgid, root string, page int) { func (self multiFrontend) RegenOnModEvent(newsgroup, msgid, root string, page int) {
@ -54,7 +40,6 @@ func (self multiFrontend) RegenOnModEvent(newsgroup, msgid, root string, page in
func MuxFrontends(fronts ...Frontend) Frontend { func MuxFrontends(fronts ...Frontend) Frontend {
var front multiFrontend var front multiFrontend
front.muxedpostchan = make(chan frontendPost, 64)
front.frontends = fronts front.frontends = fronts
return front return front
} }