Skip to content

Commit

Permalink
Merge pull request #303 from capnproto/bugfix/pipeline-promise
Browse files Browse the repository at this point in the history
Reject pipelined calls when PlaceArgs returns an error.
  • Loading branch information
zenhack authored Sep 19, 2022
2 parents cd7a85f + ad63ad6 commit e6d2ca4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion rpc/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ func (ic *importClient) Send(ctx context.Context, s capnp.Send) (*capnp.Answer,
q := ic.c.newQuestion(s.Method)

// Send call message.
var err error
syncutil.Without(&ic.c.mu, func() {
ic.c.sendMessage(ctx, func(m rpccp.Message) error {
err = ic.c.sendMessage(ctx, func(m rpccp.Message) error {
return ic.c.newImportCallMessage(m, ic.id, q.id, s)
}, func(err error) {
ic.c.mu.Lock()
Expand All @@ -120,6 +121,10 @@ func (ic *importClient) Send(ctx context.Context, s capnp.Send) (*capnp.Answer,
})
})

if err != nil {
return capnp.ErrorAnswer(s.Method, err), func() {}
}

ans := q.p.Answer()
return ans, func() {
<-ans.Done()
Expand Down
8 changes: 6 additions & 2 deletions rpc/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ func (q *question) PipelineSend(ctx context.Context, transform []capnp.PipelineO
q.mark(transform)
q2 := q.c.newQuestion(s.Method)

var err error
syncutil.Without(&q.c.mu, func() {
// Send call message.
q.c.sendMessage(ctx, func(m rpccp.Message) error {
err = q.c.sendMessage(ctx, func(m rpccp.Message) error {
return q.c.newPipelineCallMessage(m, q.id, transform, q2.id, s)
}, func(err error) {
if err != nil {
Expand All @@ -171,9 +172,12 @@ func (q *question) PipelineSend(ctx context.Context, transform []capnp.PipelineO
q2.handleCancel(ctx)
}()
})

})

if err != nil {
return capnp.ErrorAnswer(s.Method, err), func() {}
}

ans := q2.p.Answer()
return ans, func() {
<-ans.Done()
Expand Down

0 comments on commit e6d2ca4

Please sign in to comment.