Archived
1
0

try getting rid of race condition

This commit is contained in:
Jeff Becker 2017-12-28 17:11:04 -05:00
parent 95a9c1bda9
commit f4640e82c4
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -109,8 +109,6 @@ type NNTPDaemon struct {
register_connection chan *nntpConnection
deregister_connection chan *nntpConnection
// channel to load messages to infeed given their message id
infeed_load chan string
// channel for broadcasting a message to all feeds given their newsgroup, message_id
send_all_feeds chan ArticleEntry
// channel for broadcasting an ARTICLE command to all feeds in reader mode
@ -536,7 +534,6 @@ func (self *NNTPDaemon) Run() {
self.register_connection = make(chan *nntpConnection)
self.deregister_connection = make(chan *nntpConnection)
self.infeed_load = make(chan string, 128)
self.send_all_feeds = make(chan ArticleEntry)
self.activeConnections = make(map[string]*nntpConnection)
self.loadedFeeds = make(map[string]*feedState)
@ -674,8 +671,7 @@ func (self *NNTPDaemon) syncAllMessages() {
// load a message from the infeed directory
func (self *NNTPDaemon) loadFromInfeed(msgid string) {
log.Println("load from infeed", msgid)
self.infeed_load <- msgid
self.processMessage(msgid)
}
// reload all configs etc
@ -840,19 +836,16 @@ func (self *NNTPDaemon) pump_article_requests() {
articles = nil
}
func (self *NNTPDaemon) poll(worker int) {
for {
select {
case msgid := <-self.infeed_load:
func (self *NNTPDaemon) processMessage(msgid string) {
log.Println("load", msgid)
hdr := self.store.GetHeaders(msgid)
if hdr == nil {
log.Println("worker", worker, "failed to load", msgid)
log.Println("failed to load", msgid)
} else {
rollover := 100
group := hdr.Get("Newsgroups", "")
ref := hdr.Get("References", "")
log.Println("worker", worker, "got", msgid, "in", group, "references", ref != "")
log.Println("got", msgid, "in", group, "references", ref != "")
tpp, err := self.database.GetThreadsPerPage(group)
ppb, err := self.database.GetPagesPerBoard(group)
if err == nil {
@ -877,6 +870,12 @@ func (self *NNTPDaemon) poll(worker int) {
}
}
}
}
func (self *NNTPDaemon) poll(worker int) {
for {
select {
case nntp := <-self.send_all_feeds:
group := nntp.Newsgroup()
if self.Federate() {