Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rpc/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import (
"github.com/gorilla/websocket"
)

type ConnContextKeyType string

const (
pongWait = 60 * time.Second
pingPeriod = (60 * time.Second * 9) / 10
writeWait = 2 * time.Second

ConnContextKey = ConnContextKeyType("ws-conn")
)

type Conn struct {
Expand All @@ -38,6 +42,10 @@ func (c *Conn) send(msg *jsonrpc.JsonRpcResponse) {
c.sendChan <- msg.Marshal()
}

func (c *Conn) SendRaw(data []byte) {
c.sendChan <- data
}

func (s *Server) websocketHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
s.wg.Add(1)
defer s.wg.Done()
Expand Down Expand Up @@ -99,6 +107,7 @@ func (s *Server) websocketReadLoop(conn *Conn, doneChan chan struct{}) {
// Handle the request in a separate goroutine
go func() {
ctx := rpcContext.NewContextWithTraceId(context.Background(), uuid.New().String())
ctx = context.WithValue(ctx, ConnContextKey, conn)

defer func() {
if r := recover(); r != nil {
Expand Down