-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Improve treatment of SocketException #29
Conversation
@Ellerbach this try/catch it's better placed on the Http ReceiveLine or caller, isn't it? |
I think both. Reason is something can go wrong at any place in the main WebServer loop. If it goes wrong in the user call, for some reasons, the server will go down. |
As we've briefly talked on Discord, I suggest to add a global try / catch in As for the changes introduced here @Ellerbach not sure how you want to proceed... |
Yes i can.
I spent two days without internet.
Lots of rain breaking the fiber optics
…________________________________
De: José Simões ***@***.***>
Enviado: quarta-feira, 31 de março de 2021 07:59
Para: nanoframework/nanoFramework.WebServer ***@***.***>
Cc: TiagoCasas ***@***.***>; Mention ***@***.***>
Assunto: Re: [nanoframework/nanoFramework.WebServer] Exception treatment: System.Net.Sockets.SocketException (#29)
As we've briefly talked on Discord, I suggest to add a global try / catch in InputNetworkStreamWrapper.Read_HTTP_Line().
@TiagoCasas<https://github.com/TiagoCasas> can you handle this please?
As for the changes introduced here @Ellerbach<https://github.com/Ellerbach> not sure how you want to proceed...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#29 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABARQWPOODARS637HGHNOZLTGLW7HANCNFSM42CTFLCQ>.
|
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.
looks good to me but why di you moved the declared variables in the foreach loop?
I believe it generates more clarity in the source code.
For example:
bool is Route = false;
this statement is out of the "for", because it is needed later.
However
bool isFound = false;
it is not necessary outside the "for", so it was declared inside.
…________________________________
De: Laurent Ellerbach ***@***.***>
Enviado: sexta-feira, 9 de abril de 2021 16:02
Para: nanoframework/nanoFramework.WebServer ***@***.***>
Cc: TiagoCasas ***@***.***>; Mention ***@***.***>
Assunto: Re: [nanoframework/nanoFramework.WebServer] Exception treatment: System.Net.Sockets.SocketException (#29)
@Ellerbach commented on this pull request.
looks good to me but why di you moved the declared variables in the foreach loop?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#29 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABARQWIWQEWVKTILPSQKWJ3TH46LNANCNFSM42CTFLCQ>.
|
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.
Thanks for this new version. Some comments to address for performance. I think you brought clarity in the code all up. Thanks for this.
string toCompare = route.CaseSensitive ? rawUrl : rawUrl.ToLower(); | ||
|
||
if (urlParam > 0) | ||
isFound = urlParam == routeStr.Length + incForSlash; |
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.
please add { } even for 1 line if / else. This avoid a lot of issues?
&& (route.Method == string.Empty || context.Request.HttpMethod == route.Method); | ||
|
||
if (!neededName || !neededName2) | ||
continue; |
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.
Even for 1 line, please add the { }
nanoFramework.WebServer/WebServer.cs
Outdated
if (toCompare.IndexOf(routeStr) == incForSlash) | ||
CallbackRoutes route = (CallbackRoutes)rt; | ||
|
||
bool isFound; |
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.
Reason why isFoud and all the others are declared outside of the foreach loop is for performance reasons with nanoFramework. In this loop, it will be allocated and reallocated and again and again. So allocating it as high as possible will save from this behavior and optimize the speed of execution.
So please move them back where they were. If you think what they do miss clarity, feel free to add a comment :-)
nanoFramework.WebServer/WebServer.cs
Outdated
else | ||
isFound = toCompare.Length == routeStr.Length + incForSlash; | ||
|
||
// todo - please help to name the variables: neededName, neededName2 |
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.
I'm fine with the neededName. For the seconf one neededMethod can be good. And maybe what's missing is just a comment?
something like:
// neededName = matching the route name
// neededMethod = matching the method type
isFound = urlParam == routeStr.Length + incForSlash; | ||
else | ||
isFound = toCompare.Length == routeStr.Length + incForSlash; | ||
|
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.
if not found, we can continue at this point. That will improve the performance.
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.
Looks good to me! Thanks!
Description
Exception treatment: System.Net.Sockets.SocketException
Motivation and Context
When to start Web Rest server. Everything works fine. in a few minutes, it generates the excess: Exception thrown: 'System.Net.Sockets.SocketException' in System.Net.Http.dll
Types of changes
Checklist: