mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-07 00:53:01 +08:00
refactor(*) stronger concurrency locks
This commit is contained in:

committed by
Guilherme Salazar

parent
9c17f1c76f
commit
ca99408e13
2
event.go
2
event.go
@@ -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]
|
||||||
|
4
main.go
4
main.go
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user