mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-06 16:47:22 +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
|
||||
// mutated or holds references to mutable data.
|
||||
//
|
||||
// RPC exported data
|
||||
// RPC exported method
|
||||
func (s PluginServer) HandleEvent(in StartEventData, out *StepData) error {
|
||||
s.lock.RLock()
|
||||
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) {
|
||||
var handle codec.MsgpackHandle
|
||||
handle.ReaderBufferSize = 4096
|
||||
handle.WriterBufferSize = 4096
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
@@ -22,7 +24,7 @@ func runServer(listener net.Listener) {
|
||||
return
|
||||
}
|
||||
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) {
|
||||
s.lock.RLock()
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
plug, ok := s.plugins[name]
|
||||
s.lock.RUnlock()
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
@@ -84,9 +85,7 @@ func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
|
||||
config: constructor(),
|
||||
}
|
||||
|
||||
s.lock.Lock()
|
||||
s.plugins[name] = plug
|
||||
s.lock.Unlock()
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user