Skip to content
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

Finish() no longer used binding-message in Send() #689

Merged
merged 1 commit into from
Jul 6, 2021

Conversation

xinydev
Copy link
Contributor

@xinydev xinydev commented Jun 3, 2021

Finish() no longer used binding-message in Send(). and I found that some trace mechanisms must rely on Finish() to complete.

Signed-off-by: XinYang xinydev@gmail.com

Signed-off-by: XinYang <xinydev@gmail.com>
@slinkydeveloper
Copy link
Member

I think this PR is wrong, finish is invoked by the cloudevents.Client. If you're using the protocol manually, you should invoke finish by yourself

@xinydev
Copy link
Contributor Author

xinydev commented Jun 3, 2021

I think this PR is wrong, finish is invoked by the cloudevents.Client. If you're using the protocol manually, you should invoke finish by yourself

yes, when the user invokes Request() function in cloudevents.Client, the Finish() is invoked by cloudevents.Client.

but when the user invokes Send() function in cloudevents.Client, the cloudevents.Client can not get the original binding.Message, the binding.Message only exists in protocol's Send() function.

@slinkydeveloper
Copy link
Member

but when the user invokes Send() function in cloudevents.Client, the cloudevents.Client can not get the original binding.Message, the binding.Message only exists in protocol's Send() function.

Maybe that's what needs to be fixed? I mean, on the cloudevents.Client side?

@xinydev
Copy link
Contributor Author

xinydev commented Jun 4, 2021

but when the user invokes Send() function in cloudevents.Client, the cloudevents.Client can not get the original binding.Message, the binding.Message only exists in protocol's Send() function.

Maybe that's what needs to be fixed? I mean, on the cloudevents.Client side?

We can indeed fix this on the cloudevents.Client side, by changing this to invoke protocol's Request() function .

But the problem still exists, users who use the protocol manually, they invoke the protocol's Send() function, and then, they can not invoke the Finish() because the Send() function does not return the Message

The msg in L143 no longer accessible outside the protocol's send function, and we need to change the protocol's interface if we want to finish this msg out of this function.

func (p *Protocol) Send(ctx context.Context, m binding.Message, transformers ...binding.Transformer) error {
if ctx == nil {
return fmt.Errorf("nil Context")
} else if m == nil {
return fmt.Errorf("nil Message")
}
msg, err := p.Request(ctx, m, transformers...)
if err != nil && !protocol.IsACK(err) {
var res *Result
if protocol.ResultAs(err, &res) {
if message, ok := msg.(*Message); ok {
buf := new(bytes.Buffer)
buf.ReadFrom(message.BodyReader)
errorStr := buf.String()
err = NewResult(res.StatusCode, "%s", errorStr)
}
}
}
return err
}

@xinydev
Copy link
Contributor Author

xinydev commented Jun 8, 2021

@slinkydeveloper Would you please take another look?
The Message I finished is the response of the HTTP request, not the body of the request. I think the user who uses Send() function does not care about this response Message(if they care response, they should call Request() instead), they only care about the request's success or failure.

msg, err := p.Request(ctx, m, transformers...)
if err != nil && !protocol.IsACK(err) {
var res *Result
if protocol.ResultAs(err, &res) {
if message, ok := msg.(*Message); ok {
buf := new(bytes.Buffer)
buf.ReadFrom(message.BodyReader)
errorStr := buf.String()
err = NewResult(res.StatusCode, "%s", errorStr)
}
}
}
return err
}

@slinkydeveloper
Copy link
Member

@n3wscott any ideas about this one?

@xinydev
Copy link
Contributor Author

xinydev commented Jul 6, 2021

@n3wscott ping

@dan-j
Copy link
Contributor

dan-j commented Jul 6, 2021

Looking at a few of the other protocols, they all set up a deferred call to Finish(), but the http protocol doesn't. Maybe this PR is correct?

@dan-j
Copy link
Contributor

dan-j commented Jul 6, 2021

Ah, ignore my last comment, I misread the PR and just realised you explained you'd finished the response, not the original message (which is already finished)

I can't really comment on this either, I've never used the http protocol before so I don't know if this is going to cause any issues with other integrations.

@n3wscott n3wscott merged commit 94b9265 into cloudevents:main Jul 6, 2021
@n3wscott n3wscott mentioned this pull request Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants