diff --git a/conf/wide.go b/conf/wide.go index 7be32f9..006ebae 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -254,6 +254,8 @@ func FixedTimeCheckEnv() { } func checkEnv() { + defer util.Recover() + cmd := exec.Command("go", "version") buf, err := cmd.CombinedOutput() if nil != err { diff --git a/event/events.go b/event/events.go index 64ecb98..00e3eae 100644 --- a/event/events.go +++ b/event/events.go @@ -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) diff --git a/output/build.go b/output/build.go index fc188af..79913b0 100644 --- a/output/build.go +++ b/output/build.go @@ -160,6 +160,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { channelRet["output"] = "" + i18n.Get(locale, "build-succ").(string) + "\n" go func() { // go install, for subsequent gocode lib-path + defer util.Recover() + cmd := exec.Command("go", "install") cmd.Dir = curDir diff --git a/output/run.go b/output/run.go index b819f14..ae4e4a4 100644 --- a/output/run.go +++ b/output/run.go @@ -133,6 +133,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { } go func() { + defer util.Recover() + buf := outputBuf{} for { diff --git a/playground/run.go b/playground/run.go index bb6788d..cbdc18a 100644 --- a/playground/run.go +++ b/playground/run.go @@ -129,6 +129,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { } go func() { + defer util.Recover() + buf := outputBuf{} for { diff --git a/session/sessions.go b/session/sessions.go index 715526f..a05aedd 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -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: diff --git a/session/users.go b/session/users.go index 959e646..ff4499c 100644 --- a/session/users.go +++ b/session/users.go @@ -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()