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

Marker array memory leak fixes #303

Merged

Conversation

ajspera
Copy link
Contributor

@ajspera ajspera commented Dec 16, 2019

  • Same problem fixed in the previous PR for MarkerClient (Memory leak fixes #302) existed on MarkerArrayClient.

  • Also fix a race condition caused by the timeout in checkTime if a marker happened to be removed between the timeout creation and callback execution

@mxlle
Copy link

mxlle commented Jan 22, 2020

I tested these changes with my suggested fix and it helped us to solve the memory leak (at least for our use case).

It would be great if this will be merged soon.

@ajspera
Copy link
Contributor Author

ajspera commented Jan 22, 2020

@mxlle applied that.


ROS3D.MarkerArrayClient.prototype.removeMarker = function(key) {
var oldNode = this.markers[key];
if(!oldNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Null check to ensure the marker hasn't already been deleted. I had caught some race conditions between the timeout portion of MarkerClient and the stream both triggering removals for the same marker. Calling methods on something that doesn't exist will cause an error. The same race condition could happen here if someone's implementation uses removeMarker with other synchronous triggers or if a timeout feature was added to MarkerArrayClient similarly to MarkerClient. Better safe than sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like if there are null keys it means some method is doing the wrong thing, not a race condition. In JavaScript callbacks like processMessage run to completion before anything else can happen.

Instead of silently passing over these erroneous null values, it would be responsible to:

  • Log the error so it can be traced, because this should not be happening in ros3d itself.
  • Remove the null key, so we don't bloat the object keys or keep logging the same error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one in MarkerClient with the timeout option is specifically where I am saying there is a potential in library race condition where there could be 2 triggers on removeMarker for the same key.

Log the error so it can be traced, because this should not be happening in ros3d itself.

This covers the other concern I had which was users implementing their own memory cleanup where I agree a warning would be nice, maybe not an error, though, since it is benign redundancy rather than system breaking.

Remove the null key, so we don't bloat the object keys or keep logging the same error.

This already happens, the property is completely removed from the object by removeMarker via delete(this.markers[key]). Sorry I was vaguely using the term null check when in context it is an undefined property. We can specify that vs generic falsy in the if statement as well if desired.

Either way, let me know with those notes what specifically you want for changes and I'll adjust the branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now, this will work.


ROS3D.MarkerArrayClient.prototype.removeMarker = function(key) {
var oldNode = this.markers[key];
if(!oldNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like if there are null keys it means some method is doing the wrong thing, not a race condition. In JavaScript callbacks like processMessage run to completion before anything else can happen.

Instead of silently passing over these erroneous null values, it would be responsible to:

  • Log the error so it can be traced, because this should not be happening in ros3d itself.
  • Remove the null key, so we don't bloat the object keys or keep logging the same error.


ROS3D.MarkerArrayClient.prototype.removeMarker = function(key) {
var oldNode = this.markers[key];
if(!oldNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see now, this will work.

@mvollrath mvollrath merged commit e868c0b into RobotWebTools:develop Apr 22, 2020
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.

3 participants