Aias00 opened a new pull request, #3437:
URL: https://github.com/apache/dubbo-go/pull/3437

   ## Problem
   
   The global `codec` map in `remoting/codec.go` has no synchronization 
protection:
   
   ```go
   var codec = make(map[string]Codec, 2)
   
   func RegistryCodec(protocol string, codecTmp Codec) { codec[protocol] = 
codecTmp }
   func GetCodec(protocol string) Codec { return codec[protocol] }
   ```
   
   While `RegistryCodec` is currently only called during `init()`, `GetCodec` 
is called at runtime from multiple goroutines (e.g., `getty_client.go`, 
`getty_server.go`). The public `RegistryCodec` API allows runtime registration, 
which would cause a Go map concurrent read-write panic.
   
   ## Solution
   
   Add `sync.RWMutex` to protect all map access:
   
   - `RegistryCodec`: `Lock`/`Unlock` for writes
   - `GetCodec`: `RLock`/`RUnlock` for reads
   
   This follows the same pattern used throughout the project (e.g., 
`common/extension/registry_type.go`, `cluster/cluster/interceptor_invoker.go`).
   
   ## Changes
   
   - `remoting/codec.go`: Add `sync.RWMutex` protection for `codec` map
   - `remoting/codec_test.go`: Add `TestConcurrentCodecAccess` with 100 
goroutines concurrent read/write under `-race`
   
   ## Testing
   
   All tests pass with `-race` flag:
   
   ```
   go test -race -run 
"TestRegistryCodec|TestGetCodecNotFound|TestRegistryCodecOverwrite|TestConcurrentCodecAccess|TestDecodeResult"
 ./remoting/ -v
   ```
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to