changed embedded mutex to private field (#153)
Some checks failed
test / test (push) Failing after 16m53s
coverage / build (push) Failing after 17m7s
sync / sync (push) Successful in 13s

This commit is contained in:
2025-05-25 03:14:50 +05:00
committed by GitHub
parent 938ddd2ab3
commit 4a6414b2b8
2 changed files with 11 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ type httpClient struct {
funcStream client.FuncStream funcStream client.FuncStream
httpcli *http.Client httpcli *http.Client
opts client.Options opts client.Options
sync.RWMutex mu sync.RWMutex
} }
func newRequest(ctx context.Context, log logger.Logger, addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) { func newRequest(ctx context.Context, log logger.Logger, addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) {
@@ -294,18 +294,18 @@ func (c *httpClient) stream(ctx context.Context, addr string, req client.Request
} }
func (c *httpClient) newCodec(ct string) (codec.Codec, error) { func (c *httpClient) newCodec(ct string) (codec.Codec, error) {
c.RLock() c.mu.RLock()
if idx := strings.IndexRune(ct, ';'); idx >= 0 { if idx := strings.IndexRune(ct, ';'); idx >= 0 {
ct = ct[:idx] ct = ct[:idx]
} }
if cf, ok := c.opts.Codecs[ct]; ok { if cf, ok := c.opts.Codecs[ct]; ok {
c.RUnlock() c.mu.RUnlock()
return cf, nil return cf, nil
} }
c.RUnlock() c.mu.RUnlock()
return nil, codec.ErrUnknownContentType return nil, codec.ErrUnknownContentType
} }

View File

@@ -28,7 +28,7 @@ type httpStream struct {
address string address string
ct string ct string
opts client.CallOptions opts client.CallOptions
sync.RWMutex mu sync.RWMutex
} }
var errShutdown = fmt.Errorf("connection is shut down") var errShutdown = fmt.Errorf("connection is shut down")
@@ -59,8 +59,8 @@ func (h *httpStream) SendMsg(msg interface{}) error {
} }
func (h *httpStream) Send(msg interface{}) error { func (h *httpStream) Send(msg interface{}) error {
h.Lock() h.mu.Lock()
defer h.Unlock() defer h.mu.Unlock()
if h.isClosed() { if h.isClosed() {
h.err = errShutdown h.err = errShutdown
@@ -80,8 +80,8 @@ func (h *httpStream) RecvMsg(msg interface{}) error {
} }
func (h *httpStream) Recv(msg interface{}) error { func (h *httpStream) Recv(msg interface{}) error {
h.Lock() h.mu.Lock()
defer h.Unlock() defer h.mu.Unlock()
if h.isClosed() { if h.isClosed() {
h.err = errShutdown h.err = errShutdown
@@ -98,8 +98,8 @@ func (h *httpStream) Recv(msg interface{}) error {
} }
func (h *httpStream) Error() error { func (h *httpStream) Error() error {
h.RLock() h.mu.RLock()
defer h.RUnlock() defer h.mu.RUnlock()
return h.err return h.err
} }