Skip to content

Exception handling & memory leak fixes#150

Merged
josesimoes merged 11 commits into
nanoframework:developfrom
skigrinder:skigrinder---Exception-handling-&-memory-leak-fixes
Dec 29, 2020
Merged

Exception handling & memory leak fixes#150
josesimoes merged 11 commits into
nanoframework:developfrom
skigrinder:skigrinder---Exception-handling-&-memory-leak-fixes

Conversation

@skigrinder
Copy link
Copy Markdown
Contributor

Description

Modifications to Net and Net.Http libraries to fix exception handling & memory leak issues that were causing nanoFramework applications to crash

Motivation and Context

nanoFramework applications crashed when attempting to send http requests between ESP32 units.
A memory leak issue was causing nanoFramework applications to crash on ESP32 units.
No nanoFramework issues were opened for these problems

How Has This Been Tested?

Modifications were tested with multiple ESP32 units.
Http requests can now be sent/received without crashing the ESP32.
Verified that the memory leak issue associated with this library has also been fixed.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@dnfadmin
Copy link
Copy Markdown

dnfadmin commented Dec 11, 2020

CLA assistant check
All CLA requirements met.

Copy link
Copy Markdown
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read my comments on the various points.

Also do add verbose comments explaining the reasoning and why something is being done, but remove the dates and your github user name from the comment.
All changes will be logged in the file history and credited to the dev that has done them, no need to clutter the code with distracting text.

All in all, great job catching all these! 👍🏻

m_DropOldConnectionsTimer.Change( HttpConstants.DefaultKeepAliveMilliseconds, System.Threading.Timeout.Infinite );
}
}
} catch {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a comment here on why this is catching all and why there is nothing to deal with.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoFramework applications were crashing due to unhandled exceptions.
This entire section of code will eventually need to be re-worked to support persistent connections.
Some exceptions will likely require more specific action here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @josesimoes meant adding a comment in the code 😉

Copy link
Copy Markdown
Contributor Author

@skigrinder skigrinder Dec 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try/catch block removed & comments added/corrected throughout

Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
InputNetworkStreamWrapper streamWrapper = (InputNetworkStreamWrapper)m_ConnectedStreams[i];
TimeSpan timePassed = curTime - streamWrapper.m_lastUsed; // skigrinder - this is correct - original code was (m_lastUsed - curTime) - good evidence that persistent connections were never implemented here
// If the socket is old, then close and remove from the list.
if (timePassed.TotalMilliseconds > HttpConstants.DefaultKeepAliveMilliseconds) // skigrinder - original code used timePassed.Milliseconds - need to use TotalMilliseconds
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch too!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Are persistent connections a big priority?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't recall these been asked before... so the answer is no, not a big priority. But if you can have those work, that would be a nice improvement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd eventually like to take a run at persistent connections.
This would probably improve http send/receive performance.
Can we commit/merge the existing fixes first?

Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs
Comment thread nanoFramework.System.Net.Http/Http/System.Net.HttpWebRequest.cs Outdated
Copy link
Copy Markdown
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge. Just waiting for a fix on the build pipeline for the final check.

@josesimoes josesimoes merged commit 592aadc into nanoframework:develop Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants