Skip to content

Commit 54bd2d2

Browse files
committed
fix websocket
1 parent 236652b commit 54bd2d2

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

server/engine.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"sync"
2323
"time"
24+
"runtime"
2425
)
2526

2627
type DisconnectError struct {
@@ -606,6 +607,15 @@ func (self *Momonga) Unsubscribe(messageId uint16, granted int, payloads []codec
606607
}
607608

608609
func (self *Momonga) HandleConnection(conn Connection) {
610+
defer func() {
611+
if err := recover(); err != nil {
612+
const size = 64 << 10
613+
buf := make([]byte, size)
614+
buf = buf[:runtime.Stack(buf, false)]
615+
log.Error("momonga: panic serving %s: %v\n%s", conn.GetId(), err, buf)
616+
}
617+
}()
618+
609619
hndr := NewHandler(conn, self)
610620

611621
for {

server/http.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ func (self *MyHttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
3737

3838
func (self *MyHttpServer) debugRouter(w http.ResponseWriter, req *http.Request) error {
3939
switch req.URL.Path {
40+
case "/debug/vars":
41+
w.Header().Set("Content-Type", "application/json; charset=utf-8")
42+
fmt.Fprintf(w, "{\n")
43+
first := true
44+
expvar.Do(func(kv expvar.KeyValue) {
45+
if kv.Key == "cmdline" || kv.Key == "memstats"{
46+
return
47+
}
48+
if !first {
49+
fmt.Fprintf(w, ",\n")
50+
}
51+
first = false
52+
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
53+
})
54+
fmt.Fprintf(w, "\n}\n")
4055
case "/debug/pprof":
4156
httpprof.Index(w, req)
4257
case "/debug/pprof/cmdline":
@@ -126,6 +141,9 @@ func (self *MyHttpServer) apiRouter(w http.ResponseWriter, req *http.Request) er
126141
return nil
127142
case self.WebSocketMount:
128143
websocket.Handler(func(ws *websocket.Conn) {
144+
// need for bynary frame
145+
ws.PayloadType = 0x02
146+
129147
conn := NewMyConnection()
130148
conn.SetMyConnection(ws)
131149
conn.SetId(ws.RemoteAddr().String())

0 commit comments

Comments
 (0)