-
Notifications
You must be signed in to change notification settings - Fork 641
[ISSUE #4659] Fix HTTP source connector stop after receiving an invalid request #4666
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
Conversation
| log.error("[HttpSourceConnector] Malformed request. StatusCode={}", HttpResponseStatus.BAD_REQUEST.code(), t); | ||
| ctx.response().setStatusCode(HttpResponseStatus.BAD_REQUEST.code()).setStatusMessage(t.getMessage()).end(); | ||
| ctx.response().setStatusCode(HttpResponseStatus.BAD_REQUEST.code()).end(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why default err message is used instead of "attribute 'subject' cannot be null"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why default err message is used instead of "attribute 'subject' cannot be null"?
I think it's not so good to place error message here. In some cases, such as lack of attribute source, we get an error message like this from reader.toEvent().
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Missing mandatory source attribute
at [Source: (byte[])"{
"specversion": "1.0",
"type":"com.example.someevent",
"subject":"test_topic",
"datacontenttype":"text/plain",
"id": "A234-1234-1234",
"data": "aa"
}"; line: 8, column: 1]
It contains '\r\n' which cannot be used in the http status message and causes another exception in setStatusMessage.
2023-12-16 16:18:05,378 ERROR [vert.x-eventloop-thread-0] ContextBase(:) - Unhandled exception
java.lang.IllegalArgumentException: reasonPhrase contains one of the following prohibited characters: \r\n: com.fasterxml.jackson.databind.exc.MismatchedInputException: Missing mandatory source attribute
at [Source: (byte[])"{
"specversion": "1.0",
"type":"com.example.someevent",
"subject":"test_topic",
"datacontenttype":"text/plain",
"id": "A234-1234-1234",
"data": "aa"
}"; line: 8, column: 1]
at io.netty.handler.codec.http.HttpResponseStatus.<init>(HttpResponseStatus.java:558) ~[netty-codec-http-4.1.100.Final.jar:4.1.100.Final]
at io.netty.handler.codec.http.HttpResponseStatus.<init>(HttpResponseStatus.java:546) ~[netty-codec-http-4.1.100.Final.jar:4.1.100.Final]
at io.vertx.core.http.impl.Http1xServerResponse.setStatusMessage(Http1xServerResponse.java:166) ~[vertx-core-4.4.6.jar:4.4.6]
at org.apache.eventmesh.connector.http.source.connector.HttpSourceConnector.lambda$null$2(HttpSourceConnector.java:105) ~[main/:?]
As a result, the server cannot response to the sender.
Maybe it's better to response a json containing the error message, but I am still thinking about how to standardize the way the errors are described.
{
"reason" : "attribute 'subject' cannot be null"
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fungx What is the error message returned to the sender when source or subject is missing after your modification in this PR?
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #4666 +/- ##
=========================================
Coverage 17.39% 17.39%
- Complexity 1757 1760 +3
=========================================
Files 797 797
Lines 29774 29795 +21
Branches 2573 2578 +5
=========================================
+ Hits 5178 5184 +6
- Misses 24118 24131 +13
- Partials 478 480 +2 ☔ View full report in Codecov by Sentry. |
… invalid request (apache#4666)
Fixes #4659.
Motivation
Explain the content here.
Explain why you want to make the changes and what problem you're trying to solve.
see #4659
Modifications
Describe the modifications you've done.
subject,datacontenttype&databefore saving a cloudevent. Since they are required inconnectRecordbut optional in cloudevents.Documentation