-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.help wantedplannedThis issue/proposal is planned into our next steps.This issue/proposal is planned into our next steps.
Description
When standard routing is used, gf will read the entire body content first, and then do parameter binding. Therefore, when there is a file parameter in the canonical route, gf will first read the content of the file into memory. When there are multiple file upload requests at the same time, it is easy to blow up the system memory.
1. What version of Go and system type/arch are you using?
go version go1.20 linux/amd64
2. What version of GoFrame are you using?
v2.5.2
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
package main
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type UploadReq struct {
g.Meta `path:"/upload" method:"POST" tags:"Upload" mime:"multipart/form-data" summary:"上传文件"`
File *ghttp.UploadFile `p:"file" type:"file" dc:"选择上传文件"`
}
type UploadRes struct{}
type cUpload struct{}
func (u cUpload) Upload(ctx context.Context, req *UploadReq) (*UploadRes, error) {
return nil, nil
}
func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(cUpload{})
})
s.SetClientMaxBodySize(100 * 1024 * 1024)
s.Run()
}5. What did you expect to see?
When there are multiple upload requests at the same time, the memory overhead will not be too large.
6. What did you see instead?
Read the file data and write the data to the disk at the same time, instead of reading all the data and then writing it to the disk.
gqcn
Metadata
Metadata
Assignees
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.help wantedplannedThis issue/proposal is planned into our next steps.This issue/proposal is planned into our next steps.