panic recover in gorutine
This commit is contained in:
parent
e10eadb1e0
commit
eaaee8443a
|
@ -254,6 +254,8 @@ func FixedTimeCheckEnv() {
|
|||
}
|
||||
|
||||
func checkEnv() {
|
||||
defer util.Recover()
|
||||
|
||||
cmd := exec.Command("go", "version")
|
||||
buf, err := cmd.CombinedOutput()
|
||||
if nil != err {
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/b3log/wide/log"
|
||||
"github.com/b3log/wide/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -69,6 +70,8 @@ var UserEventQueues = queues{}
|
|||
// Load initializes the event handling.
|
||||
func Load() {
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
for event := range EventQueue {
|
||||
logger.Debugf("Received a global event [code=%d]", event.Code)
|
||||
|
||||
|
@ -106,6 +109,8 @@ func (ueqs queues) New(sid string) *UserEventQueue {
|
|||
ueqs[sid] = q
|
||||
|
||||
go func() { // start listening
|
||||
defer util.Recover()
|
||||
|
||||
for evt := range q.Queue {
|
||||
logger.Debugf("Session [%s] received an event [%d]", sid, evt.Code)
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
channelRet["output"] = "<span class='build-succ'>" + i18n.Get(locale, "build-succ").(string) + "</span>\n"
|
||||
|
||||
go func() { // go install, for subsequent gocode lib-path
|
||||
defer util.Recover()
|
||||
|
||||
cmd := exec.Command("go", "install")
|
||||
cmd.Dir = curDir
|
||||
|
||||
|
|
|
@ -133,6 +133,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
buf := outputBuf{}
|
||||
|
||||
for {
|
||||
|
|
|
@ -129,6 +129,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
buf := outputBuf{}
|
||||
|
||||
for {
|
||||
|
|
|
@ -101,6 +101,8 @@ var mutex sync.Mutex
|
|||
// Invalid sessions: sessions that not used within 30 minutes, refers to WideSession.Updated field.
|
||||
func FixedTimeRelease() {
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
for _ = range time.Tick(time.Hour) {
|
||||
hour, _ := time.ParseDuration("-30m")
|
||||
threshold := time.Now().Add(hour)
|
||||
|
@ -133,6 +135,8 @@ func (u *userReport) report() string {
|
|||
// FixedTimeReport reports the Wide sessions status periodically (10 minutes).
|
||||
func FixedTimeReport() {
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
for _ = range time.Tick(10 * time.Minute) {
|
||||
users := userReports{}
|
||||
processSum := 0
|
||||
|
@ -332,6 +336,8 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS
|
|||
}
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
workspaces := filepath.SplitList(conf.GetUserWorkspace(username))
|
||||
for _, workspace := range workspaces {
|
||||
filepath.Walk(filepath.Join(workspace, "src"), func(dirPath string, f os.FileInfo, err error) error {
|
||||
|
@ -356,6 +362,8 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS
|
|||
}()
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
|
|
|
@ -293,6 +293,8 @@ func SignUpUserHandler(w http.ResponseWriter, r *http.Request) {
|
|||
// Main goal of this function is to save user session content, for restoring session content while user open Wide next time.
|
||||
func FixedTimeSave() {
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
for _ = range time.Tick(time.Minute) {
|
||||
users := getOnlineUsers()
|
||||
|
||||
|
|
Loading…
Reference in New Issue