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

An error occurs in a multi-coroutine scenario #7066

Open
exasasas opened this issue Jun 13, 2024 · 3 comments
Open

An error occurs in a multi-coroutine scenario #7066

exasasas opened this issue Jun 13, 2024 · 3 comments
Assignees
Labels
type:question general questions

Comments

@exasasas
Copy link

exasasas commented Jun 13, 2024

I have started a program with many coroutines. In this case, when my gorm has been executed for a period of time, it returns an empty struct but does not return an error. This seems to happen randomly because I There are 2 pods running at the same time but always appear in one of them. no return ErrRecordNotFound or other err but return empty struct

This is my config

db, _ := gorm.Open(mysql.Open(dsn_master), &gorm.Config{Logger: logger.New(
		Writer{}, // io writer
		logger.Config{
			SlowThreshold: time.Second / 2, // Slow SQL threshold
			LogLevel:      logger.Info,     // Log level
		},
	)})
	db.Use(dbresolver.Register(dbresolver.Config{
		Sources:  []gorm.Dialector{mysql.Open(dsn_master)},
		Replicas: []gorm.Dialector{mysql.Open(dsn_slave)},
		Policy:   dbresolver.RandomPolicy{},
	}).
		SetConnMaxIdleTime(time.Hour).
		SetConnMaxLifetime(time.Hour).
		SetMaxIdleConns(500).
		SetMaxOpenConns(4000))

@exasasas exasasas added the type:question general questions label Jun 13, 2024
@ivila
Copy link

ivila commented Jun 14, 2024

Please submit a runable example, or we are just wasting time here.

@exasasas
Copy link
Author

Please submit a runable example, or we are just wasting time here.

It is a simple query. I have a go program that has opened many coroutines. These coroutines will sleep. The query is executed in the coroutines. After running for some time, the results are generated.

	err := db.Where("id = ?", id).First(&data).Error
	if err != nil {
		return nil, err
	}

@ivila
Copy link

ivila commented Jun 14, 2024

Please submit a runable example, or we are just wasting time here.

A runable example contains huge information than what you provided:

  1. the go.mod: the version of GORM and the driver version you are using
  2. the codes: how your codes runs, did you accidently eat the errors?(for example, a gorm plugin)

It's very recommended that you should write one rather than just doing questions and answers, like I said, it's just wasting time here.

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

No branches or pull requests

3 participants