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))

Comment From: ivila

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

Comment From: exasasas

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
    }

Comment From: ivila

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.

Comment From: gisard

This may be because your data insertion side is later than the data reading side

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days