try fixing deadlock
This commit is contained in:
		@@ -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})
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -171,13 +171,12 @@ func (lc *liveChan) handleMessage(front *httpFrontend, cmd *liveCommand) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type httpFrontend struct {
 | 
					type httpFrontend struct {
 | 
				
			||||||
	modui        ModUI
 | 
						modui    ModUI
 | 
				
			||||||
	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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	secret string
 | 
						secret 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,33 +401,33 @@ 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
 | 
					 | 
				
			||||||
			msgid := nntp.MessageID()
 | 
					 | 
				
			||||||
			group := nntp.Newsgroup()
 | 
					 | 
				
			||||||
			ref := nntp.Reference()
 | 
					 | 
				
			||||||
			self.informLiveUI(msgid, ref, group)
 | 
					 | 
				
			||||||
			if len(ref) > 0 {
 | 
					 | 
				
			||||||
				msgid = ref
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			entry := ArticleEntry{msgid, group}
 | 
					 | 
				
			||||||
			// regnerate thread
 | 
					 | 
				
			||||||
			self.regenThreadChan <- entry
 | 
					 | 
				
			||||||
			// regen the newsgroup we're in
 | 
					 | 
				
			||||||
			// TODO: regen only what we need to
 | 
					 | 
				
			||||||
			pages := self.daemon.database.GetGroupPageCount(group)
 | 
					 | 
				
			||||||
			// regen all pages
 | 
					 | 
				
			||||||
			var page int64
 | 
					 | 
				
			||||||
			for ; page < pages; page++ {
 | 
					 | 
				
			||||||
				req := groupRegenRequest{
 | 
					 | 
				
			||||||
					group: group,
 | 
					 | 
				
			||||||
					page:  int(page),
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				self.regenGroupChan <- req
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					func (self *httpFrontend) HandleNewPost(nntp frontendPost) {
 | 
				
			||||||
 | 
						msgid := nntp.MessageID()
 | 
				
			||||||
 | 
						group := nntp.Newsgroup()
 | 
				
			||||||
 | 
						ref := nntp.Reference()
 | 
				
			||||||
 | 
						go self.informLiveUI(msgid, ref, group)
 | 
				
			||||||
 | 
						if len(ref) > 0 {
 | 
				
			||||||
 | 
							msgid = ref
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						entry := ArticleEntry{msgid, group}
 | 
				
			||||||
 | 
						// regnerate thread
 | 
				
			||||||
 | 
						self.regenThreadChan <- entry
 | 
				
			||||||
 | 
						// regen the newsgroup we're in
 | 
				
			||||||
 | 
						// TODO: regen only what we need to
 | 
				
			||||||
 | 
						pages := self.daemon.database.GetGroupPageCount(group)
 | 
				
			||||||
 | 
						// regen all pages
 | 
				
			||||||
 | 
						var page int64
 | 
				
			||||||
 | 
						for ; page < pages; page++ {
 | 
				
			||||||
 | 
							req := groupRegenRequest{
 | 
				
			||||||
 | 
								group: group,
 | 
				
			||||||
 | 
								page:  int(page),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							self.regenGroupChan <- req
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// create a new captcha, return as json object
 | 
					// create a new captcha, return as json object
 | 
				
			||||||
func (self *httpFrontend) new_captcha_json(wr http.ResponseWriter, r *http.Request) {
 | 
					func (self *httpFrontend) new_captcha_json(wr http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
@@ -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()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,7 @@ 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
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (self multiFrontend) AllowNewsgroup(newsgroup string) bool {
 | 
					func (self multiFrontend) AllowNewsgroup(newsgroup string) bool {
 | 
				
			||||||
@@ -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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user