Skip to content

Avoid deadlocking connection on tube name validation errors #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
33 changes: 22 additions & 11 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ func (c *Conn) cmd(t *Tube, ts *TubeSet, body []byte, op string, args ...interfa
}
}

// tube name checking
if err := validateTubes(t, ts); err != nil {
return req{}, err
}

r := req{c.c.Next(), op}
c.c.StartRequest(r.id)
defer c.c.EndRequest(r.id)
err := c.adjustTubes(t, ts)
if err != nil {
return req{}, err
}
c.adjustTubes(t, ts)
if body != nil {
args = append(args, len(body))
}
Expand All @@ -95,27 +97,37 @@ func (c *Conn) cmd(t *Tube, ts *TubeSet, body []byte, op string, args ...interfa
c.c.W.Write(body)
c.c.W.Write(crnl)
}
err = c.c.W.Flush()
err := c.c.W.Flush()
if err != nil {
return req{}, ConnError{c, op, err}
}
return r, nil
}

func (c *Conn) adjustTubes(t *Tube, ts *TubeSet) error {
if t != nil && t.Name != c.used {
func validateTubes(t *Tube, ts *TubeSet) error {
if t != nil {
if err := checkName(t.Name); err != nil {
return err
}
}
if ts != nil {
for s := range ts.Name {
if err := checkName(s); err != nil {
return err
}
}
}
return nil
}

func (c *Conn) adjustTubes(t *Tube, ts *TubeSet) {
if t != nil && t.Name != c.used {
c.printLine("use", t.Name)
c.used = t.Name
}
if ts != nil {
for s := range ts.Name {
if !c.watched[s] {
if err := checkName(s); err != nil {
return err
}
c.printLine("watch", s)
}
}
Expand All @@ -129,7 +141,6 @@ func (c *Conn) adjustTubes(t *Tube, ts *TubeSet) error {
c.watched[s] = true
}
}
return nil
}

// does not flush
Expand Down