Skip to content

Check connection liveness before sending query #882

Closed
@methane

Description

@methane

ErrBadConn can be returned only when it's safe to retry. After sending query, we can't use it.

People must use DB.SetConnMaxLifetime to avoid connection closed from MySQL server, router, middlewares, to avoid such situation.

But we can save 90% cases by checking connection liveness before sending query.
Since Go 1.9, SyscallConn can be used to call system call directly. We can try non-blocking 1-byte read to detect connection closed by peer.

Ref: #657
Ref: golang/go#28607

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions