Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Map object destruction is hanging #1657

Merged
merged 3 commits into from
Jun 4, 2015
Merged

Conversation

tmpsantos
Copy link
Contributor

Under some scenarios, destroying the Map object is hanging. This is specially easy to reproduce if we trigger rendering and when a request fails with a few other pending, we delete the Map object.

This is probably happening because there are pending requests holding the Map Thread's main loop alive and deadlocking somewhere. In the past we had a method for canceling all the requests that belong to an Environment, but now we need to make sure that every object doing requests is canceling pending requests at the dtor.

@tmpsantos
Copy link
Contributor Author

/cc @mikemorris

@tmpsantos
Copy link
Contributor Author

Progress update: the resource loading is starting at the moment we set the style instead of when we call renderStill(). If something goes wrong during this time window we never get notified because renderStill() sets the callback for reporting errors.

@tmpsantos tmpsantos force-pushed the 1657-map_object_hanging_on_dtor branch from 4b9b1d9 to 1cc33ee Compare June 1, 2015 14:51
@tmpsantos tmpsantos added ready and removed in progress ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Jun 1, 2015
@tmpsantos tmpsantos force-pushed the 1657-map_object_hanging_on_dtor branch from 1cc33ee to 48bd2a8 Compare June 1, 2015 14:57
@tmpsantos
Copy link
Contributor Author

@jfirebaugh @kkaefer please take a look at this on too

@mikemorris
Copy link
Contributor

@tmpsantos Still seeing hangs as a race condition when testing node-mbgl against this. When three requests emit errors to the log and then the error callback is returned and the destructor is called, the process hangs. When all four requests emit errors before the callback returns, the process exits cleanly.

I'm testing this by enabling the returns an error test in node-mbgl.

@@ -47,6 +47,14 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map
}

MapContext::~MapContext() {
if (resourceLoader) {
// This is likely to be called only on unit tests when
// the MapContext is not bound to a Map object.
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid code that is specific to unit tests? This sort of defeats the purpose of having unit tests when we special case them in our regular code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we avoid code that is specific to unit tests? This sort of defeats the purpose of having unit tests when we special case them in our regular code.

I agree. Gonna change this.

@kkaefer
Copy link
Member

kkaefer commented Jun 2, 2015

In what cases do we not have a ResourceLoader object?

@tmpsantos tmpsantos force-pushed the 1657-map_object_hanging_on_dtor branch from 48bd2a8 to df07fce Compare June 2, 2015 19:18
tmpsantos added 3 commits June 4, 2015 14:44
We start loading the resources at the moment we set the style, but we
set the callback for error notification at renderStill(), which happen
afterwards.

If some error occurs in this short window, it was never being notified.
Now we save the last error and we check after we set the callback.
The util::Thread will call the stop() method of the MapContext's RunLoop
which will wait for the pending tasks tied to it to complete.

If we have a request that is timeout'ing, this could mean a really long
wait. Instead, we now send a cleanup message that will reset all the
attributes first (canceling the pending requests) so the the MapContext
gets destructed quickly.
Test whenever destroying a Map object with requests pending
works and is done quickly.

The test injects artificial delays in selected requests and
tries to destroy the Map object afterwards.

Currently glyph requests are skipped because there is a bug
being worked on in a different issue.
@tmpsantos tmpsantos force-pushed the 1657-map_object_hanging_on_dtor branch from df07fce to 1408370 Compare June 4, 2015 11:45
@tmpsantos tmpsantos merged commit 1408370 into master Jun 4, 2015
@mourner mourner removed the ready label Jun 4, 2015
@tmpsantos tmpsantos deleted the 1657-map_object_hanging_on_dtor branch June 4, 2015 12:18
@jfirebaugh
Copy link
Contributor

👍

Did this fix #1477?

@tmpsantos
Copy link
Contributor Author

Did this fix #1477?

Yes! 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants