Skip to content

When multiple instances of Duktape are running concurrently console output/errors are saved to the wrong Duktape object #28

@jezwhite

Description

@jezwhite

All,

I have multiple instances of Duktape in-flight controlled via an external event loop (Mojo). When one instance of Duktape is waiting for an event to complete (ie, fetching data from the web) console output and errors are written to the wrong Duktape instance (looks like the last created).

I assume this is a valid use case? Other than console output/errors, everything else seems ok.

The following example will show the issue:

   use warnings;
   use strict;
   use Data::Dumper;
   use JavaScript::Duktape::XS;

   my $options = {
     gather_stats     => 1,
     save_messages    => 1,
   };

   my $instanceOne = JavaScript::Duktape::XS->new($options);   
   my $instanceTwo = JavaScript::Duktape::XS->new($options);   
   $instanceOne->eval('console.log("hello from instance one")');

   print "output from instance one: \n";
   print Dumper $instanceOne->get_msgs();
   print "output from instance two: \n";
   print Dumper $instanceTwo->get_msgs();

When run, the output will be shown for $instanceTwo rather than $instanceOne that ran the code.

I believe the problem is with

typedef struct ConsoleConfig {
    ConsoleHandler* handler;
    void* data;
} ConsoleConfig;

In duk_Console.c

As it's a global and not on an object basis, it's causing the problem. I think the solution would be to associate a pointer from the perl side (ie, Duk*) into the actual duktape (ie, ctx*) and remove the global struct above.

Thoughts?

Regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions