rgbkrk / libvirt-go

[DEPRECATED] Go bindings for libvirt
https://github.com/libvirt/libvirt-go
MIT License
166 stars 50 forks source link

events: handle overflow of callback IDs #93

Closed vincentbernat closed 8 years ago

vincentbernat commented 8 years ago

When registering/deregistering a lot of callbacks, in a long-running process, it may be possible for nextGoCallbackId to overflow. Therefore, after incrementing it, check that its number is not already used. This should be a rare event as the map should stay quite sparse.

rgbkrk commented 8 years ago

Since nextGoCallbackId is always incrementing by one, if/when an overflow happens wouldn't the map be "filled" at that point resulting in an infinite loop?

vincentbernat commented 8 years ago

Nope. The typical use case is that you have events setup since the application was started (for example, they get the goCallbackId 2) and you have events that are created and teared down during the lifetime of the application. So, you have a lot of free ID. But once you overflow, you will reuse 2 which was not free. 3 is free.