ik icon indicating copy to clipboard operation
ik copied to clipboard

Fix race between flush and Emit.

Open methane opened this issue 11 years ago • 3 comments

Emit() may be called from multiple goroutine. flush() is also called from anther goroutine. To protect buffer from race, single goroutine should handle all emit() and flush().

WIP: I have not run this code yet. Hopefully, I'll test in this week.

methane avatar Jun 11 '14 18:06 methane

At the moment Output.Emit() may only be called from the single router that is not reentrant. Therefore, it doesn't need to be thread-safe. In addition, as PluginInstance.Run() is supposed to be periodically called by the supervisor so it can detect the healthiness of the spawnee (in other words, the implementor of the method should make it return ik.Continue at a certain interval if she wants to keep it running), the creation of the timer at the top of the function seems inappropriate.

moriyoshi avatar Jun 12 '14 03:06 moriyoshi

Having said that, it's always a good thing for an output plugin to not consume much time in its Emit(), and so is offloading the communication to another goroutine.

moriyoshi avatar Jun 12 '14 03:06 moriyoshi

After a short discussion with @methane, I had an impression that the router should be reentrant for the sake of performance, because message passing between the plugins and the router otherwise needs to be guarded by either unbuffered or buffered (when the multiple routers get spawned) channels.

moriyoshi avatar Jun 12 '14 06:06 moriyoshi