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

Crash after Name or service not known error #26

Closed
gchudnov opened this issue May 15, 2015 · 6 comments
Closed

Crash after Name or service not known error #26

gchudnov opened this issue May 15, 2015 · 6 comments

Comments

@gchudnov
Copy link
Contributor

When running two requests one after the other, If the first request contains a bad URL, the second request crashes the app.

The first request reports an error (as expected):

Error: Error resolving 'www.mezilla.org': Name or service not known
    at Error (native)
    at WebKit.<anonymous> (/home/gchudnov/Projects/node-webkitgtk/webkitgtk.js:609:27)
    at Timer.listOnTimeout (timers.js:89:15)

The second request terminates the app (unexpected):

iojs crashed with SIGSEGV in WebView::PngWrite()

Sample code (might be a bit long):

var WebKit = require('../');
var expect = require('expect.js');
var fs = require('fs');
var path  = require('path');

describe.only("Experiment", function suite() {
  this.timeout(10000);

  var w;

  before(function(cb) {
    var inst = new WebKit();
    var initOptions = {
      width: 1024,
      height: 768,
      depth: 32
    };

    inst.init(initOptions, function(err) {
      if(err) {
        cb(err);
      } else {
        w = inst;
        cb();
      }
    });
  });


  it("reports an error on Bad URL", function(done) {

    var href = "https://www.mezilla.org/en-US/";
    var filePath = path.resolve(__dirname, './shots/out1.png');

    function onRendered(err) {
      console.log('ON_RENDERED', err);
      console.log('DONE!');
      done();
    }

    w.once('idle', function() {
      w.png(filePath, onRendered);
    });

    var loadParams = {
    };

    w.load(href, loadParams, function(err) {
      if(err) {
        console.log('LOAD_ERROR', err);
        done(err);
      }
    });

  });

  it("should render Good URL after a bad one", function(done) {

    var href = "https://www.mozilla.org/en-US/";
    var filePath = path.resolve(__dirname, './shots/out2.png');

    function onRendered(err) {
      console.log('ON_RENDERED', err);
      console.log('DONE!');
      done();
    }

    w.once('idle', function() {
      w.png(filePath, onRendered);
    });

    var loadParams = {
    };

    w.load(href, loadParams, function(err) {
      if(err) {
        console.log('LOAD_ERROR', err);
        done(err);
      }
    });

  });

});
@kapouer
Copy link
Owner

kapouer commented May 15, 2015

I reproduce indeed using your test.
The first idle event listener is called despite the first load failure (i've not decided yet if this is a
bad or good behavior...)
so when you call done() the first time and reuse the instance, it's still being used by the first test !

@kapouer
Copy link
Owner

kapouer commented May 15, 2015

You can easily work around that crash if you set the 'idle' listener in the load callback iff there is no error at that stage.

@kapouer
Copy link
Owner

kapouer commented May 16, 2015

Two successive calls of png() are responsible for the crash.
I've pushed version 1.18.9, making your code throw an exception instead of segfaulting.

@gchudnov
Copy link
Contributor Author

Got it,
Thank you!

@gchudnov
Copy link
Contributor Author

So, it is better to set up idle and load handlers after .load completes without an error. Right?

@gchudnov
Copy link
Contributor Author

In the following code that uses the async to print images one after the other, the second load callback (marked as '---> LOAD-COMPLETE') is never called:

    var arr = [
      "https://www.mezilla.org/en-US/",
      "https://www.google.com"
    ];
    async.eachSeries(arr, function(it, cb) {
      var href = it;
      var filePath = path.resolve(__dirname, './shots/outN.png');
      console.error('---> LOAD', href);
      w.load(href, {}, function(err) {
        console.error('---> LOAD-COMPLETE');
        if(err) {
          console.error('---> LOAD-ERR', err);
          cb();
        } else {
          console.error('---> SETTING-IDLE');
          w.once('idle', function() {
            w.png(filePath, function(err) {
              console.error('---> PNG', href, err);
              cb();
            });
          });
        }
      });
    }, function(err) {
      done(err);
    });

Not sure what is the problem?

A complete test might something like this:

var WebKit = require('../');
var expect = require('expect.js');
var fs = require('fs');
var path = require('path');
var async = require('async');

describe.only("ordered png render calls", function suite() {
  this.timeout(20000);
  var w;
  before(function(cb) {
    var inst = new WebKit();
    inst.init({}, function(err) {
      if (err) return cb(err);
      w = inst;
      cb();
    });
  });
  it("should not stall", function(done) {
    var arr = [
      "https://www.mezilla.org/en-US/",
      "https://www.google.com/",
      "https://www.debian.org/"
    ];
    async.eachSeries(arr, function(it, cb) {
      var href = it;
      var filePath = path.resolve(__dirname, './shots/outN.png');
      console.error('---> LOAD', href);
      w.load(href, {}, function(err) {
        console.error('---> LOAD-COMPLETE');  // <--- callback not called for the second time
        if(err) {
          console.error('---> LOAD-ERR', err);
          cb();
        } else {
          console.error('---> SETTING-IDLE');
          w.once('idle', function() {
            w.png(filePath, function(err) {
              console.error('---> PNG', href, err);
              cb();
            });
          });
        }
      });
    }, function(err) {
      done(err);
    });
  });
});

And the same problem reproduced in case of 404:
e.g.

    var arr = [
      "http://www.google.com/asdsad"
      "https://www.google.com/"
    ];

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

No branches or pull requests

2 participants