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

🐛 [Bug]: Memory data disorder #2612

Closed
3 tasks done
qiannianshaonian opened this issue Aug 31, 2023 · 3 comments
Closed
3 tasks done

🐛 [Bug]: Memory data disorder #2612

qiannianshaonian opened this issue Aug 31, 2023 · 3 comments

Comments

@qiannianshaonian
Copy link

Bug Description

my request method is "GET" or "POST",
but when i write route info in my sqlDB,
i found the method is changed "POS"

1693462097196

How to Reproduce

Steps to reproduce the behavior:

  1. start httpServer by debug
  2. start httpClient
  3. you can find this bug

Expected Behavior

Reproduction steps:

  1. start httpServer by debug
  2. start httpClient
  3. you can find this bug

1693462097196
//code in attachs
code.zip

Fiber Version

github.com/gofiber/fiber/v2 v2.49.0

Code Snippet (optional)

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New(
		fiber.Config{
			RequestMethods: []string{"POST", "GET", "PUT", "HEAD"},
			// 进行各个参数设置
			ServerHeader: "test",
			// 设置请求body大小限制
			BodyLimit: 10 * 1024 * 1024 * 1024,
			// 设置请求并发限制
			Concurrency:          1024 * 1024 * 1024,
			ReadBufferSize:       128 * 1024,
			WriteBufferSize:      128 * 1024,
			CompressedFileSuffix: ".gz",
			ReduceMemoryUsage:    false,
			DisableKeepalive:     true,
			// 禁用启动时的信息展示
			DisableStartupMessage: true,
		},
	)
	app.All("*", microservice)
	log.Fatal(app.Listen(":8000"))
}

func microservice(c *fiber.Ctx) error {
	method := strings.ToUpper(c.Method())
	path := c.Path()
	doTracing(path, method)
	msg := fmt.Sprintf("1111 %s", c.Params("*"))
	return c.SendString(msg)
}

func doTracing(path, method string) {
	t := GatewayRouterForm{
		Method: method,
		ReqURL: path + method,
	}
	if t.Method == "POS" {
		fmt.Println(".....")
	}
	fmt.Printf("....1111   %p %s %v \n", &t, t.ReqURL, t)
	go next(t)
}
func next(t GatewayRouterForm) {
	fmt.Printf("....222222   %p %s %v \n", &t, t.ReqURL, t)
	if t.Method == "POS" {
		fmt.Printf("....3333   %p %s %v \n", &t, t.ReqURL, t)
	}
}

type GatewayRouterForm struct {
	// 请求Method
	Method string
	// 请求的全url
	ReqURL string
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@welcome
Copy link

welcome bot commented Aug 31, 2023

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87
Copy link
Member

this is why fiber and fasthttp is so fast

we reuse the requests and responses for subsequent requests

read this
https://docs.gofiber.io/#zero-allocation

the solution is to simply make a copy of the data for everything that breaks out of this context, such as a go routine that runs alongside it or other processes that want to get the data afterwards, so that it is not overwritten by the replacement in the next request response process.

image

@qiannianshaonian
Copy link
Author

thank you
This is a great technique, and I will learn to master it

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

No branches or pull requests

2 participants