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

Fix several issues in node bindings #9554

Merged
merged 3 commits into from
Jul 24, 2017
Merged

Fix several issues in node bindings #9554

merged 3 commits into from
Jul 24, 2017

Conversation

jfirebaugh
Copy link
Contributor

  • Protect against request implementations that throw -- I had a buggy test and noticed that this was causing a segfault.
  • Reset lastError state when appropriate -- this was causing spurious errors when reusing a Map object for multiple renders.

// Protect ourselves from `request` implementations that try to release Zalgo.
// http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony
try {
request(req, function() {

Choose a reason for hiding this comment

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

Wrapping an async function in a try/catch always set off a🚨 in my head. Which function in here can throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing should throw. This is the API defending itself against badly behaved request functions that do throw -- better to be defensive than crash in this situation.

@kkaefer kkaefer added Core The cross-platform C++ core, aka mbgl Node.js node-mapbox-gl-native labels Jul 20, 2017
@jfirebaugh jfirebaugh requested a review from kkaefer July 21, 2017 15:30
var map = new mbgl.Map({
request: function() {
throw new Error('message');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test that first calls the callback, and then throws? This should ensure that the callback doesn't get invoked twice. Maybe also a test that has two invocations of callback.

@jfirebaugh jfirebaugh changed the base branch from fix-8812 to master July 21, 2017 16:31
});
map.load(mockfs.style_vector);
map.render({ zoom: 16 }, function(err, pixels) {
t.error(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

This test passes even without the code changes. Can we add a check to make sure the render function is called only once ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is an add-on requested by @kkaefer to an add-on to the real fix here. Can I 🙏 just merge this so that @bsudekum is unblocked?

@jfirebaugh jfirebaugh merged commit a178248 into master Jul 24, 2017
@jfirebaugh jfirebaugh deleted the node-fixes branch July 24, 2017 22:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl Node.js node-mapbox-gl-native
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants