Skip to content

Commit

Permalink
Merge pull request #397 from zenhack/without-handleBootstrap
Browse files Browse the repository at this point in the history
handleBootstrap: avoid a use of syncutil.Without()
  • Loading branch information
zenhack authored Dec 22, 2022
2 parents 34de47d + c80375e commit ebd690c
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,49 +612,48 @@ func (c *Conn) handleBootstrap(ctx context.Context, id answerID) error {
rl := &releaseList{}
defer rl.Release()

c.lk.Lock()
defer c.lk.Unlock()

if c.lk.answers[id] != nil {
return rpcerr.Failedf("incoming bootstrap: answer ID %d reused", id)
}

var (
err error
ans = answer{c: c, id: id}
)

syncutil.Without(&c.lk, func() {
ans.ret, ans.sendMsg, ans.msgReleaser, err = c.newReturn()
if err == nil {
ans.ret.SetAnswerId(uint32(id))
ans.ret.SetReleaseParamCaps(false)
ans.ret, ans.sendMsg, ans.msgReleaser, err = c.newReturn()
if err == nil {
ans.ret.SetAnswerId(uint32(id))
ans.ret.SetReleaseParamCaps(false)
}

syncutil.With(&c.lk, func() {
if c.lk.answers[id] != nil {
rl.Add(ans.msgReleaser.Decr)
err = rpcerr.Failedf("incoming bootstrap: answer ID %d reused", id)
return
}
})

if err != nil {
err = rpcerr.Annotate(err, "incoming bootstrap")
c.lk.answers[id] = errorAnswer(c, id, err)
c.er.ReportError(err)
return nil
}
if err != nil {
err = rpcerr.Annotate(err, "incoming bootstrap")
c.lk.answers[id] = errorAnswer(c, id, err)
c.er.ReportError(err)
return
}

c.lk.answers[id] = &ans
if !c.bootstrap.IsValid() {
ans.sendException(rl, exc.New(exc.Failed, "", "vat does not expose a public/bootstrap interface"))
return nil
}
if err := ans.setBootstrap(c.bootstrap.AddRef()); err != nil {
ans.sendException(rl, err)
return nil
}
err = ans.sendReturn(rl)
if err != nil {
// Answer cannot possibly encounter a Finish, since we still
// haven't returned to receive().
panic(err)
}
return nil
c.lk.answers[id] = &ans
if !c.bootstrap.IsValid() {
ans.sendException(rl, exc.New(exc.Failed, "", "vat does not expose a public/bootstrap interface"))
return
}
if err := ans.setBootstrap(c.bootstrap.AddRef()); err != nil {
ans.sendException(rl, err)
return
}
err = ans.sendReturn(rl)
if err != nil {
// Answer cannot possibly encounter a Finish, since we still
// haven't returned to receive().
panic(err)
}
})
return err
}

func (c *Conn) handleCall(ctx context.Context, call rpccp.Call, releaseCall capnp.ReleaseFunc) error {
Expand Down

0 comments on commit ebd690c

Please sign in to comment.