Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Stack overflow with Postgres in v1.31.x #7699

@unknwon

Description

@unknwon

Description

When using gorm v1.31.0 or v1.31.1 with PostgreSQL, certain queries cause a stack overflow (infinite recursion). The issue does not occur with MySQL or SQLite, only PostgreSQL.

Steps to reproduce

  1. Use gorm v1.31.0 or v1.31.1 with gorm.io/driver/postgres
  2. Run queries that involve DELETE with WHERE clause

Stack trace

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

goroutine 296 gp=0xc00063efc0 m=5 mp=0xc0000a0008 [running]:
gorm.io/gorm/callbacks.BuildQuerySQL(0xc02073ea20)
    gorm.io/[email protected]/callbacks/query.go:36 +0x453a
gorm.io/gorm/callbacks.Query(0xc02073ea20)
    gorm.io/[email protected]/callbacks/query.go:16 +0x6b
gorm.io/gorm.(*processor).Execute(0xc0011dad70, 0xc02073ea20)
    gorm.io/[email protected]/callbacks.go:136 +0xb59
gorm.io/gorm.(*Statement).AddVar(0xc0207461e0, {0x481e4f0, 0xc0207461e0}, {0xc0207057f0, 0x1, 0xc021589630?})
    gorm.io/[email protected]/statement.go:240 +0x1c8a
gorm.io/gorm/clause.Expr.Build(...)
    gorm.io/[email protected]/clause/expression.go:53 +0x8e2
...

Environment

  • gorm version: v1.31.0, v1.31.1
  • gorm.io/driver/postgres: v1.6.0
  • github.com/jackc/pgx/v5: v5.6.0 and v5.8.0 (tried both)
  • Go version: 1.25.6
  • Database: PostgreSQL

Workaround

Using gorm v1.25.12 or v1.30.5 does not exhibit this issue.

Additional context

Discovered while attempting to upgrade gorm in https://github.com/gogs/gogs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions