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

[ISSUE #4659] Fix HTTP source connector stop after receiving an invalid request #4666

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

Fungx
Copy link
Contributor

@Fungx Fungx commented Dec 16, 2023

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.

  • Check arrtibutes subject, datacontenttype & data before saving a cloudevent. Since they are required in connectRecord but optional in cloudevents.
  • Use default status message in failure response.

Documentation

  • Does this pull request introduce a new feature?no
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

Comment on lines 104 to 106
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();
});
Copy link
Member

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"?

Copy link
Contributor Author

@Fungx Fungx Dec 16, 2023

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" 
}

Copy link
Member

@pandaapo pandaapo Dec 16, 2023

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?

@xwm1992 xwm1992 added this to the 1.10 milestone Dec 16, 2023
Copy link

codecov bot commented Dec 16, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (b85a58c) 17.39% compared to head (454f4a7) 17.39%.
Report is 2 commits behind head on master.

Files Patch % Lines
...tor/http/source/connector/HttpSourceConnector.java 40.00% 3 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

@mxsm mxsm merged commit d625790 into apache:master Dec 16, 2023
13 checks passed
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.

[Bug] HTTP source connector stop after receiving an invalid request
5 participants