Skip to content

Commit

Permalink
websocket: fix transfer conn concurrent op
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Nov 20, 2023
1 parent f02683a commit 8512d68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nbhttp/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func (p *Parser) Read(data []byte) error {
return nil
}

var c byte
var start = 0
var offset = len(p.cache)
if offset > 0 {
Expand All @@ -161,6 +160,7 @@ UPGRADER:
return err
}

var c byte
for i := offset; i < len(data); i++ {
if p.Reader != nil {
goto UPGRADER
Expand Down
2 changes: 1 addition & 1 deletion nbhttp/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (c *Conn) nextFrame() (opcode MessageType, body []byte, ok, fin, res1, res2
func (c *Conn) Read(p *nbhttp.Parser, data []byte) error {
oldLen := len(c.buffer)
readLimit := c.Engine.ReadLimit
if readLimit > 0 && ((oldLen+len(data) > readLimit) || ((oldLen + len(c.message) + len(data)) > readLimit)) {
if readLimit > 0 && (oldLen+len(data) > readLimit) {
return nbhttp.ErrTooLong
}

Expand Down
8 changes: 6 additions & 2 deletions nbhttp/websocket/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
parser.Execute = nbhttp.SyncExecutor
}
wsc = NewConn(u, vt, subprotocol, compress, false)
nbc.SetSession(wsc)
parser.Reader = wsc
parser.Engine = engine
nbc.SetSession(parser)
nbc.OnData(func(c *nbio.Conn, data []byte) {
defer func() {
if err := recover(); err != nil {
Expand Down Expand Up @@ -349,7 +351,9 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
parser.Execute = nbhttp.SyncExecutor
}
wsc = NewConn(u, nbc, subprotocol, compress, false)
nbc.SetSession(wsc)
parser.Reader = wsc
parser.Engine = engine
nbc.SetSession(parser)
nbc.OnData(func(c *nbio.Conn, data []byte) {
defer func() {
if err := recover(); err != nil {
Expand Down

0 comments on commit 8512d68

Please sign in to comment.