-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Invalid HttpRequest kills HttpServer #3222
Comments
This comment was originally written by [email protected] Also Dart can't handle reverse proxy requests from nginx (a very popular story we should be supporting), this is the StackTrace I get: Unhandled exception: |
Maybe instead of throwing exceptions we should propagate the exception object to the HttpServer onError handler. Then the HttpServer user is in control and can ignore the error, log it, or shut down the server as he sees fit. I agree that the server should not stop because someone fires an invalid request at it. What do you think Søren? Set owner to @sgjesse. |
We need a simple way of handling errors during request processing that goes for both exceptions during the HTTP parsing and exceptions while actually running the request handler. I think there should be some default handling that will return a response with status code 400 (Bad Request) if HTTP parsing fails and status code 500 (Internal Server Error) if an exception is thrown in the request handler. In both these cases the underlying socket connection should be closed after the response has been sent. Added Started label. |
Regarding comment #1: The reason for this failure is that the nginx reverse proxy talks HTTP 1.0 with the Dart server. For HTTP 1.0 the content length header needs to be set before sending any content. At the moment an exception is thrown if content length is not set before sending data for HTTP 1.0. With the following nginx configuration: location /dart { And this Dart code void main() { the nginx reverse proxy configuration works when navigating to http://localhost/dart/xxx. Nginx have the configuration proxy_http_version which can be set to 1.1 which might also help. However it requires nginx 1.1.4, which I don't have at hand. We could consider to buffer all output for HTTP 1.0 if the content length is not set and send it all with content length when available. |
This comment was originally written by [email protected] I have nginx 1.1.9 and can confirm that this works: location / { Nginx + Dart at: http://dart-todos.ubixar.com :) |
The main reason for the Dart HttpServer throwing an uncaught exception and terminating in these error cases is that there is no error handler set on the HttpServer instance. Adding that HttpServer server; should print the error and keep the server running. It will not return an error response to the client just close the underlying socket connection. |
Added this to the M1 milestone. |
This comment was originally written by [email protected] Regarding comment #7: Setting the "proxy_http_version 1.1;" does not work for me. dart code: var server = new HttpServer(); nginx configuration: 1 in 10 page reloads it works but in most cases the nginx returns the 502 http exception. tested both on windows7-64 and ubunty |
The original bug report here was that the HttpServer would die with an unhandled exception on invalid requests if no error handler was registered. This is working as designed. You should always register an error handler on your HttpServer. Please file new bugs for other issues so we can track them properly. Thanks. Added AsDesigned label. |
Removed Area-IO label. |
Changes: ``` > git log --format="%C(auto) %h %s" 51435ef..c4e9ddc https://dart.googlesource.com/pub.git/+/c4e9ddc8 Extend retries for file-ops on windows (#3451) https://dart.googlesource.com/pub.git/+/6aeb1795 Upgrade package:lints to 2.0.0 (#3445) https://dart.googlesource.com/pub.git/+/73ea9a98 Roll tar to 0.5.5+1 (#3447) https://dart.googlesource.com/pub.git/+/2dc887fe Add env var for writing golden files (#3222) https://dart.googlesource.com/pub.git/+/764500b8 List all files in pub publish (#3440) https://dart.googlesource.com/pub.git/+/0b52e6a8 Remove debug print (#3441) https://dart.googlesource.com/pub.git/+/ea070238 Merge pull request #3443 from jonasfj/master https://dart.googlesource.com/pub.git/+/bffd1267 Merge branch 'cherry-pick-for-2.17.2' https://dart.googlesource.com/pub.git/+/c66381c5 Make `name` field of `_UserInfo` nullable. Fix #3424 (#3442) https://dart.googlesource.com/pub.git/+/cecc8e3c Handle broken response from userinfo_endpoint (#3427) https://dart.googlesource.com/pub.git/+/6c635040 Make `name` field of `_UserInfo` nullable. Fix #3424 (#3442) https://dart.googlesource.com/pub.git/+/6f20a94b Handle missing pubspec.lock in dependency_services list (#3439) https://dart.googlesource.com/pub.git/+/0ad17e84 Handle broken response from userinfo_endpoint (#3427) https://dart.googlesource.com/pub.git/+/153ef061 `pub add` create top-level attribute in block-style if possible. (#3423) https://dart.googlesource.com/pub.git/+/3b96f910 Handle error code 183 on windows (#3426) https://dart.googlesource.com/pub.git/+/9eb6428c Ignore `pubspec_overrides.yaml` for `publish` command (#3419) ``` Diff: https://dart.googlesource.com/pub.git/+/51435efcd574b7bc18d47a5dd620cb9759dea8f8~..c4e9ddc888c3aa89ef4462f0c4298929191e32b9/ Change-Id: I6dacb3e95c6399d3fb5cf340b5d0e5cded270684 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247962 Commit-Queue: Sigurd Meldgaard <[email protected]> Reviewed-by: Jonas Jensen <[email protected]>
This issue was originally filed by [email protected]
I was doing 'telnet localhost 8000' and the Dart HttpServer crashes on some simple mal-formed HTTP:
GET /
and got:
Unhandled exception:
HttpParserException: Invalid request URI
0. Function: '[email protected]' url: 'dart:io' line:510 col:388
1. Function: '_HttpConnection@19ffb8b9._onConnectionClosed@19ffb8b9' url: 'dart:io' line:497 col:133
2. Function: '_HttpConnectionBase@19ffb8b9._onError@19ffb8b9' url: 'dart:io' line:487 col:237
3. Function: '[email protected]' url: 'dart:io' line:497 col:1
4. Function: '[email protected]' url: 'dart:io' line:673 col:22
5. Function: '_HttpConnectionBase@19ffb8b9._onData@19ffb8b9' url: 'dart:io' line:486 col:71
6. Function: '_SocketBase@19ffb8b9._multiplex@19ffb8b9' url: 'dart:io' line:926 col:1
7. Function: '[email protected]' url: 'dart:io' line:942 col:142
8. Function: '_ReceivePortImpl@38422f21._handleMessage@38422f21' url: 'dart:isolate' line:19 col:46
GET / h
listening on 8000...
Unhandled exception:
HttpParserException: Failed to parse HTTP
0. Function: '[email protected]' url: 'dart:io' line:510 col:388
1. Function: '_HttpConnection@19ffb8b9._onConnectionClosed@19ffb8b9' url: 'dart:io' line:497 col:133
2. Function: '_HttpConnectionBase@19ffb8b9._onError@19ffb8b9' url: 'dart:io' line:487 col:237
3. Function: '[email protected]' url: 'dart:io' line:497 col:1
4. Function: '[email protected]' url: 'dart:io' line:673 col:22
5. Function: '_HttpConnectionBase@19ffb8b9._onData@19ffb8b9' url: 'dart:io' line:486 col:71
6. Function: '_SocketBase@19ffb8b9._multiplex@19ffb8b9' url: 'dart:io' line:926 col:1
7. Function: '[email protected]' url: 'dart:io' line:942 col:142
8. Function: '_ReceivePortImpl@38422f21._handleMessage@38422f21' url: 'dart:isolate' line:19 col:46
The Http Server should be resilient enough not to crash when it receives invalid HTTP.
If throwing these exceptions is expected behaviour how do we catch it and prevent it from taking the server down?
The text was updated successfully, but these errors were encountered: