Skip to content

Commit

Permalink
fixbug: fix occasional RPC blocking issue due to coroutine scheduling…
Browse files Browse the repository at this point in the history
… timing, leading to a nil chan during the pushBackMsg call.
  • Loading branch information
lbbniu committed Jan 11, 2024
1 parent b34089b commit dd26961
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tars/statf.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ type StatFHelper struct {
mStatCountFromServer map[statf.StatMicMsgHead]int
}

func newStatFHelper(app *application) *StatFHelper {
return &StatFHelper{
chStatInfo: make(chan StatInfo, app.ServerConfig().StatReportChannelBufLen),
mStatInfo: make(map[statf.StatMicMsgHead]statf.StatMicMsgBody),
mStatCount: make(map[statf.StatMicMsgHead]int),
app: app,
chStatInfoFromServer: make(chan StatInfo, app.ServerConfig().StatReportChannelBufLen),
mStatInfoFromServer: make(map[statf.StatMicMsgHead]statf.StatMicMsgBody),
mStatCountFromServer: make(map[statf.StatMicMsgHead]int),
}
}

// Init the StatFHelper
func (s *StatFHelper) Init(comm *Communicator, servant string) {
s.servant = servant
s.app = comm.app
s.chStatInfo = make(chan StatInfo, s.app.ServerConfig().StatReportChannelBufLen)
s.chStatInfoFromServer = make(chan StatInfo, s.app.ServerConfig().StatReportChannelBufLen)
s.mStatInfo = make(map[statf.StatMicMsgHead]statf.StatMicMsgBody)
s.mStatCount = make(map[statf.StatMicMsgHead]int)
s.mStatInfoFromServer = make(map[statf.StatMicMsgHead]statf.StatMicMsgBody)
s.mStatCountFromServer = make(map[statf.StatMicMsgHead]int)
s.comm = comm
s.sf = new(statf.StatF)
s.comm.StringToProxy(s.servant, s.sf)
Expand Down Expand Up @@ -175,7 +180,7 @@ func initReport(app *application) error {
return fmt.Errorf("stat init error")
}
comm := app.Communicator()
StatReport = new(StatFHelper)
StatReport = newStatFHelper(app)
StatReport.Init(comm, cfg.Stat)
statInited <- struct{}{}
go StatReport.Run()
Expand Down

0 comments on commit dd26961

Please sign in to comment.