panic recover in gorutine

This commit is contained in:
Liang Ding 2015-03-16 11:24:55 +08:00
parent e10eadb1e0
commit eaaee8443a
7 changed files with 23 additions and 0 deletions

View File

@ -254,6 +254,8 @@ func FixedTimeCheckEnv() {
} }
func checkEnv() { func checkEnv() {
defer util.Recover()
cmd := exec.Command("go", "version") cmd := exec.Command("go", "version")
buf, err := cmd.CombinedOutput() buf, err := cmd.CombinedOutput()
if nil != err { if nil != err {

View File

@ -19,6 +19,7 @@ import (
"os" "os"
"github.com/b3log/wide/log" "github.com/b3log/wide/log"
"github.com/b3log/wide/util"
) )
const ( const (
@ -69,6 +70,8 @@ var UserEventQueues = queues{}
// Load initializes the event handling. // Load initializes the event handling.
func Load() { func Load() {
go func() { go func() {
defer util.Recover()
for event := range EventQueue { for event := range EventQueue {
logger.Debugf("Received a global event [code=%d]", event.Code) logger.Debugf("Received a global event [code=%d]", event.Code)
@ -106,6 +109,8 @@ func (ueqs queues) New(sid string) *UserEventQueue {
ueqs[sid] = q ueqs[sid] = q
go func() { // start listening go func() { // start listening
defer util.Recover()
for evt := range q.Queue { for evt := range q.Queue {
logger.Debugf("Session [%s] received an event [%d]", sid, evt.Code) logger.Debugf("Session [%s] received an event [%d]", sid, evt.Code)

View File

@ -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" channelRet["output"] = "<span class='build-succ'>" + i18n.Get(locale, "build-succ").(string) + "</span>\n"
go func() { // go install, for subsequent gocode lib-path go func() { // go install, for subsequent gocode lib-path
defer util.Recover()
cmd := exec.Command("go", "install") cmd := exec.Command("go", "install")
cmd.Dir = curDir cmd.Dir = curDir

View File

@ -133,6 +133,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
go func() { go func() {
defer util.Recover()
buf := outputBuf{} buf := outputBuf{}
for { for {

View File

@ -129,6 +129,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
go func() { go func() {
defer util.Recover()
buf := outputBuf{} buf := outputBuf{}
for { for {

View File

@ -101,6 +101,8 @@ var mutex sync.Mutex
// Invalid sessions: sessions that not used within 30 minutes, refers to WideSession.Updated field. // Invalid sessions: sessions that not used within 30 minutes, refers to WideSession.Updated field.
func FixedTimeRelease() { func FixedTimeRelease() {
go func() { go func() {
defer util.Recover()
for _ = range time.Tick(time.Hour) { for _ = range time.Tick(time.Hour) {
hour, _ := time.ParseDuration("-30m") hour, _ := time.ParseDuration("-30m")
threshold := time.Now().Add(hour) threshold := time.Now().Add(hour)
@ -133,6 +135,8 @@ func (u *userReport) report() string {
// FixedTimeReport reports the Wide sessions status periodically (10 minutes). // FixedTimeReport reports the Wide sessions status periodically (10 minutes).
func FixedTimeReport() { func FixedTimeReport() {
go func() { go func() {
defer util.Recover()
for _ = range time.Tick(10 * time.Minute) { for _ = range time.Tick(10 * time.Minute) {
users := userReports{} users := userReports{}
processSum := 0 processSum := 0
@ -332,6 +336,8 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS
} }
go func() { go func() {
defer util.Recover()
workspaces := filepath.SplitList(conf.GetUserWorkspace(username)) workspaces := filepath.SplitList(conf.GetUserWorkspace(username))
for _, workspace := range workspaces { for _, workspace := range workspaces {
filepath.Walk(filepath.Join(workspace, "src"), func(dirPath string, f os.FileInfo, err error) error { 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() { go func() {
defer util.Recover()
for { for {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:

View File

@ -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. // Main goal of this function is to save user session content, for restoring session content while user open Wide next time.
func FixedTimeSave() { func FixedTimeSave() {
go func() { go func() {
defer util.Recover()
for _ = range time.Tick(time.Minute) { for _ = range time.Tick(time.Minute) {
users := getOnlineUsers() users := getOnlineUsers()