commit 73057ed29848ed62d363ea708e95156998a18c79
parent e4eab6cf9aacfdc7e5531ee3412ad06b6e0c705b
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 23 Oct 2023 09:13:36 +0900
fix bug where rFlush() panics
Diffstat:
2 files changed, 3 insertions(+), 17 deletions(-)
diff --git a/client.go b/client.go
@@ -5,8 +5,6 @@ import (
"fmt"
"io"
"sync"
-
- "log"
)
type Client struct {
@@ -46,7 +44,6 @@ func (c *Client) Stop() {
// TODO: check all goroutines are stopped.
c.wg.Wait()
close(c.errc)
- log.Println("client stopped")
}
func (c *Client) mSize() uint32 {
@@ -76,7 +73,6 @@ func (c *Client) runListener(ctx context.Context, r io.Reader) <-chan Msg {
wg.Wait()
close(rmsgc)
c.wg.Done()
- log.Println("listener stopped")
}()
for {
select {
@@ -125,7 +121,6 @@ func (c *Client) runSpeaker(ctx context.Context, w io.Writer) chan<- Msg {
c.wg.Add(1)
tmsgc := make(chan Msg, 3)
go func() {
- defer log.Println("speaker stopped")
defer c.wg.Done()
for {
select {
@@ -165,7 +160,6 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- Msg, rmsgc <-c
defer func() {
wg.Wait()
c.wg.Done()
- log.Println("rmsg stopped")
}()
rPool := make(map[uint16]*clientReq)
for {
@@ -217,7 +211,6 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- Msg, rmsgc <-c
close(reqc)
close(tmsgc)
c.wg.Done()
- log.Println("tmsg stopped")
}()
for {
select {
diff --git a/server.go b/server.go
@@ -142,6 +142,9 @@ func getReq(r io.Reader, s *Server) (*Req, error) {
req.ifcall = bufMsg(buf)
return req, err
}
+ if ifcall, ok := req.ifcall.(*TFlush); ok {
+ req.oldReq, _ = req.srv.rPool.lookup(ifcall.OldTag())
+ }
if s.chatty9P {
fmt.Fprintf(os.Stderr, "<-- %v\n", req.ifcall)
}
@@ -254,16 +257,6 @@ func rAttach(r *Req, err error) {
}
func sFlush(ctx context.Context, s *Server, r *Req) {
- // BUG: if the oldTag does not exists and client sends another message
- // before the server sends Rflush message, and getReq() adds the
- // newly arrived message to the rPool, and then sFlush lookup()s the
- // updated rPool, this lookup() can return the newly arrived req instead
- // of nil. In this case, the server will flush the newly arrived message
- // or if rFlush is called before the r.cancel is defined, the server will
- // panic.
- r.oldReq can be the newly arrived request.
- ifcall := r.ifcall.(*TFlush)
- r.oldReq, _ = s.rPool.lookup(ifcall.OldTag())
respond(ctx, r, nil)
}