Skip to content

Commit

Permalink
Merge pull request #15 from fanzhe328/master
Browse files Browse the repository at this point in the history
fix concurrent invoke bug
  • Loading branch information
fanzhe328 authored Jul 11, 2022
2 parents f1a63e4 + c9ab0e4 commit a9b5698
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fc/runtime_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type runtimeAPIClient struct {
baseURL string
userAgent string
httpClient *http.Client
buffer *bytes.Buffer
}

func newRuntimeAPIClient(address string) *runtimeAPIClient {
Expand All @@ -63,7 +62,7 @@ func newRuntimeAPIClient(address string) *runtimeAPIClient {
}
endpoint := "http://" + address + "/" + apiVersion + "/runtime/invocation/"
userAgent := "aliyun-fc-go/" + runtime.Version()
return &runtimeAPIClient{endpoint, userAgent, client, bytes.NewBuffer(nil)}
return &runtimeAPIClient{endpoint, userAgent, client}
}

type invoke struct {
Expand Down Expand Up @@ -121,15 +120,15 @@ func (c *runtimeAPIClient) next() (*invoke, error) {
return nil, fmt.Errorf("failed to GET %s: got unexpected status code: %d", url, resp.StatusCode)
}

c.buffer.Reset()
_, err = c.buffer.ReadFrom(resp.Body)
payload := new(bytes.Buffer)
_, err = payload.ReadFrom(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read the invoke payload: %v", err)
}

return &invoke{
id: resp.Header.Get(headerFCRequestID),
payload: c.buffer.Bytes(),
payload: payload.Bytes(),
headers: resp.Header,
client: c,
}, nil
Expand Down

0 comments on commit a9b5698

Please sign in to comment.