Comments (8)
I see. Unfortunately, I don't currently have extra bandwidth to work on that. Contributions are very welcome.
from node-libvirt.
I started working on the implementation, and it seems to work, but i've a problem, and may be you can help me to solve this one.
I registered a callback for a lifecycle event, and, if i started a vm, libvirt call the "C" handler you specified for this kind of event : domain_event_lifecycle_callback
But there is a problem with the opaque pointer you used to pass the node object containing the hypervisor and the JS callback : the opaque pointer address is the "same" (if i print the address of the opaque pointer where you define it, and if i print it in the domain_event_lifecycle_callback function, i got the same value) but it generate a segfault as soon as you used it :
Local hyp = obj->Get(domain_event_hypervisor_symbol)->ToObject();
it seems the Object has been freed between the callback registering and the callback call (when a lifecycle event occurs).
I tried to pass a simple integer pointer (allocated on the heap with a c++ new) instead of the Persistent, and i got it with the correct value in the domain_event_lifecycle_callback function.
Any idea ? i'm not very familar with node API and variable scopes...
from node-libvirt.
I see, you should be able to call hypervisor->Ref() before calling the JS callback and once it comes back you call hypervisor->Unref(). I'm doing a similar thing in https://github.com/c4milo/node-inotify/blob/master/src/bindings.cc#L154 and https://github.com/c4milo/node-inotify/blob/master/src/bindings.cc#L302
from node-libvirt.
it will increase the reference count and will avoid v8 GC to release that object.
from node-libvirt.
The released object is not the Hypervisor, but the Persistent v8 Object you set-up as "opaque" (the void* libvirt give you back in handler) :
Persistent<Object> opaque = Persistent<Object>::New(Object::New());
opaque->Set(domain_event_hypervisor_symbol, args.This());
opaque->Set(domain_event_callback_symbol, jscallback);
Hypervisor *hypervisor = ObjectWrap::Unwrap<Hypervisor>(args.This());
int ret = virConnectDomainEventRegisterAny( hypervisor->conn_,
domain != NULL ? domain->domain() : NULL,
evtype, callback,
&opaque, domain_event_free);
from node-libvirt.
I found the fix for this issue. It comes from the way you pass the opaque object.
You use &opaque, which means "the address" of the persitent handle "opaque". But this variable is allocated on the stack, so only available in the function it is defined.
What you want to pass to the virConnectDomainEventRegisterAny is not the v8::Persistent address, but the v8::Object address. Handle (so Persistent) overload the * operator to get the embedded v8::Value pointer.
This is a bit strange at the syntax level, but you need to use *opaque (instead of &opaque) which return the address of the Object encapsulated in the Persistent.
There is nothing to change is the callback itself .. it works right.
I've some improvements to make, and i'll propose you a pull request for libvirt event management.
Anthony.
from node-libvirt.
hey @atoy40, great that you made it work! Thanks a lot for your help and apologies for my lack of timely and accurate responses. The truth is, It will take me a bit of time to wrap my head around this project again since I'm currently working on very different things.
from node-libvirt.
No problem :)
from node-libvirt.
Related Issues (20)
- lookupDomainById returns empty object HOT 11
- Parent objects get garbage collected before children' async operations finish which can lead to a crash HOT 3
- Error information can be lost during high concurrency
- Error objects become invalid and cause a crash (test-case supplied) HOT 7
- lookupStorageVolumeByVolume is not implemented HOT 4
- tests != docs. HOT 6
- Events not firing HOT 6
- v2.0.0 promisification changes HOT 6
- list by domain name? HOT 6
- Error with connection pointers HOT 4
- Domain migration with options fails with sigfault HOT 1
- lookupDomainByUUID HOT 3
- set/get secret value do not work properly HOT 4
- Domain clonage
- npm install in windows error
- Current version in npm does not have the latest fixes. HOT 6
- How to listen for all domain events from hypervisor
- Maintainers? HOT 3
- Crashes when using events
- Can't install on Centos 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-libvirt.