refactor(*) stronger concurrency locks

This commit is contained in:
Javier Guerra
2019-11-19 11:49:03 -05:00
committed by Guilherme Salazar
parent 9c17f1c76f
commit ca99408e13
3 changed files with 7 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ type eventData struct {
// they all receive the same object instance, so should be careful if it's // they all receive the same object instance, so should be careful if it's
// mutated or holds references to mutable data. // mutated or holds references to mutable data.
// //
// RPC exported data // RPC exported method
func (s PluginServer) HandleEvent(in StartEventData, out *StepData) error { func (s PluginServer) HandleEvent(in StartEventData, out *StepData) error {
s.lock.RLock() s.lock.RLock()
instance, ok := s.instances[in.InstanceId] instance, ok := s.instances[in.InstanceId]

View File

@@ -14,6 +14,8 @@ var socket = flag.String("socket", "", "Socket to listen into")
func runServer(listener net.Listener) { func runServer(listener net.Listener) {
var handle codec.MsgpackHandle var handle codec.MsgpackHandle
handle.ReaderBufferSize = 4096
handle.WriterBufferSize = 4096
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
@@ -22,7 +24,7 @@ func runServer(listener net.Listener) {
return return
} }
rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, &handle) rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, &handle)
rpc.ServeCodec(rpcCodec) go rpc.ServeCodec(rpcCodec)
} }
} }

View File

@@ -52,9 +52,10 @@ type pluginData struct {
} }
func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) { func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
s.lock.RLock() s.lock.Lock()
defer s.lock.Unlock()
plug, ok := s.plugins[name] plug, ok := s.plugins[name]
s.lock.RUnlock()
if ok { if ok {
return return
} }
@@ -84,9 +85,7 @@ func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
config: constructor(), config: constructor(),
} }
s.lock.Lock()
s.plugins[name] = plug s.plugins[name] = plug
s.lock.Unlock()
return return
} }