Skip to content

database/gdb: context canceled #4034

@weimx2023

Description

@weimx2023

Go version

go version go1.22.5 windows/amd64

GoFrame version

v2.8.2

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

MYSQL

DDL

CREATE TABLE user (
  id INT PRIMARY KEY AUTO_INCREMENT,
  passport VARCHAR(255),
  password VARCHAR(255), 
  nickname VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CONFIG

if the config.yaml set the tranTimeout

  default:
    link: "mysql:root:xxxxx@tcp(localhost:3306)/test?loc=Local"
    debug: true
#    queryTimeout: "30s"  # 查询语句超时时长
    tranTimeout: "30s"   # 事务处理超时时长

CODE

test go code just using transaction

func main() {
	ctx := gctx.New()

	err := saveDeviceAndToken(ctx)
	if err != nil {
		return
	}

}

func saveDeviceAndToken(ctx context.Context) error {
	return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
		// 保存应用设备信息
		if err := saveAppDevice(ctx, tx); err != nil {
			return err
		}

		return nil
	})
}

func saveAppDevice(ctx context.Context, tx gdb.TX) error {

	_, err := g.DB().Model("user").Safe().Ctx(ctx).TX(tx).Data(g.Map{
		"passport": "111",
		"password": "222",
		"nickname": "333",
	}).Save()
	return err
}

What did you see happen?

2024-12-11 19:18:40.571 [DEBU] {78439ed3571b10182fd5de54b618aea2} [ 7 ms] [default] [test] [rows:0 ] [txid:1] BEGIN (IosolationLevel: Default, ReadOnly: false)
2024-12-11 19:18:40.571 [ERRO] {78439ed3571b10182fd5de54b618aea2} [ 0 ms] [default] [test] [rows:0 ] [txid:1] SHOW FULL COLUMNS FROM user
Error: context canceled

What did you expect to see?

the transaction will execute OK!

Metadata

Metadata

Assignees

Labels

bugIt is confirmed a bug, but don't worry, we'll handle it.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions