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

[Bug] HTTP source connector stop after receiving an invalid request #4659

Closed
3 tasks done
Fungx opened this issue Dec 16, 2023 · 2 comments · Fixed by #4666
Closed
3 tasks done

[Bug] HTTP source connector stop after receiving an invalid request #4659

Fungx opened this issue Dec 16, 2023 · 2 comments · Fixed by #4666
Labels
bug Something isn't working

Comments

@Fungx
Copy link
Contributor

Fungx commented Dec 16, 2023

Search before asking

  • I had searched in the issues and found no similar issues.

Environment

Linux

EventMesh version

master

What happened

HTTP source connector stop after receiving an request without attribute subject and never response again.

How to reproduce

Reproduce

  1. start http connector server
  2. send an invalid request without subject, such as
curl --location --request POST 'http://localhost:3755/test' \
--header 'ce-id: 11' \
--header 'ce-specversion: 1.0' \
--header 'ce-type: com.example.someevent' \
--header 'ce-source: /mycontext' \
# --header 'ce-subject: test' \
--header 'Content-Type: text/plain' \
--data-raw 'aaa'
  1. http connector server stop forever

Analysis

In HttpSourceConnector#poll, the conversion from cloudevent to connectRecord is performed.
image

If a cloudevent contains null subject, connectRecord.addExtension("topic", event.getSubject()) will throw unexpected NPE, which will stop the connector server.
image

Fix

Check subject before saving cloudevents. We don't need to check other attributes like id, source, type,etc. Because they are required arrtibutes of cloudevents and cloudevents-sdk will do the check in toEvent().

VertxMessageFactory.createReader(ctx.request())
                    .map(r -> {
                        CloudEvent event = r.toEvent();
                        if (event.getSubject() == null) {
                            throw new IllegalStateException("attribute 'subject' cannot be null");
                        }
                        return event;
                    })
setting others...

Debug logs

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@Fungx Fungx added the bug Something isn't working label Dec 16, 2023
@Pil0tXia
Copy link
Member

Good. Is there a way for the sender to get that there is an error in one of the packets sent without looking at the EM logs?

@Fungx
Copy link
Contributor Author

Fungx commented Dec 16, 2023

Good. Is there a way for the sender to get that there is an error in one of the packets sent without looking at the EM logs?

Sender can get it from the http status code. 400 will be returned if there is an error in the conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants