Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用接口报错 data race #538

Open
chuan-T opened this issue Nov 25, 2021 · 1 comment
Open

调用接口报错 data race #538

chuan-T opened this issue Nov 25, 2021 · 1 comment

Comments

@chuan-T
Copy link

chuan-T commented Nov 25, 2021

如下所示去调用

	request := requests.NewCommonRequest()
	request.Method = "GET"
	request.Scheme = "https" // https | http request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com"
	request.Version = "2018-05-01"
	request.ApiName = "QueryMessage"
	request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com"

	request.QueryParams["RegionId"] = "ap-southeast-1"
	request.QueryParams["MessageId"] = messageId

	response, err := ar.cli.ProcessCommonRequest(request)

error log

WARNING: DATA RACE
Read at 0x00c0038e86a0 by goroutine 348:
crypto/tls.(*Config).Clone()
 /usr/local/go/src/crypto/tls/common.go:768 +0x757
 net/http.cloneTLSConfig()
 /usr/local/go/src/net/http/transport.go:2856 +0xb1
 net/http.(*persistConn).addTLS()
 /usr/local/go/src/net/http/transport.go:1510 +0x45
 net/http.(*Transport).dialConn()
 /usr/local/go/src/net/http/transport.go:1610 +0x31b3
 net/http.(*Transport).dialConnFor()
 /usr/local/go/src/net/http/transport.go:1442 +0x151

Previous write at 0x00c0038e86a0 by goroutine 274:
 github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).DoActionWithSigner()
/go/pkg/mod/github.com/aliyun/[email protected]/sdk/client.go:587 +0x220f
...

SDK 版本: v1.61.1347

@ljluestc
Copy link

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
    "log"
)

func makeRequest(messageId string) {
    // Create a new Client for each request to avoid concurrency issues
    client, err := sdk.NewClientWithAccessKey("region", "accessKeyId", "accessKeySecret")
    if err != nil {
        log.Fatalf("Error creating client: %v", err)
    }

    request := requests.NewCommonRequest()
    request.Method = "GET"
    request.Scheme = "https"
    request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com"
    request.ApiName = "QueryMessage"
    request.Version = "2018-05-01"
    request.QueryParams["RegionId"] = "ap-southeast-1"
    request.QueryParams["MessageId"] = messageId

    // Send the request
    response, err := client.ProcessCommonRequest(request)
    if err != nil {
        log.Printf("Error processing request: %v", err)
        return
    }

    log.Printf("Response: %v", response)
}

func main() {
    // Example call for a single message ID
    makeRequest("your-message-id")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants