并发订阅pubsub导致致命错误:concurrent map writes

问题描述 投票:0回答:0

使用以下设置在 Go 中订阅 GCP pubsub 时

sub.ReceiveSettings.Synchronous = false
sub.ReceiveSettings.NumGoroutines = 10
sub.ReceiveSettings.MaxOutstandingMessages = 100

在连接到http端点时最后做一些业务处理如下:

t := http.DefaultTransport.(*http.Transport).Clone()
t.MaxIdleConns = 120
t.MaxConnsPerHost = 200
t.MaxIdleConnsPerHost = 120
request, _:= http.NewRequest("POST", "EndPoint", bytes.NewBuffer(jsonValue))
request.Header.Set(graphql.Api_Key, graphql.Api_Key_Value)
client := &http.Client{Timeout: time.Second * constants.QUERY_REQUEST_TIMEOUT, Transport: t}
response, graphQLError := client.Do(request)

当流量到达点 response, _:= client.Do(request),我得到以下致命错误 “并发映射写入”和致命跟踪,因此服务器 pod 进入重启模式。

go http httpclient publish-subscribe
© www.soinside.com 2019 - 2024. All rights reserved.