{"record":{"id":"723648230db8f725","repo":"go-sql-driver/mysql","slug":"busy-buffer","errorCode":null,"errorMessage":"busy buffer","messagePattern":"busy buffer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":30,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n)\n\n// Various errors the driver might return. Can change between driver versions.\nvar (\n\tErrInvalidConn       = errors.New(\"invalid connection\")\n\tErrMalformPkt        = errors.New(\"malformed packet\")\n\tErrNoTLS             = errors.New(\"TLS requested but server does not support TLS\")\n\tErrCleartextPassword = errors.New(\"this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN\")\n\tErrNativePassword    = errors.New(\"this user requires mysql native password authentication\")\n\tErrOldPassword       = errors.New(\"this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords\")\n\tErrUnknownPlugin     = errors.New(\"this authentication plugin is not supported\")\n\tErrOldProtocol       = errors.New(\"MySQL server does not support required protocol 41+\")\n\tErrPktSync           = errors.New(\"commands out of sync. You can't run this command now\")\n\tErrPktSyncMul        = errors.New(\"commands out of sync. Did you run multiple statements at once?\")\n\tErrPktTooLarge       = errors.New(\"packet for query is too large. Try adjusting the `Config.MaxAllowedPacket`\")\n\tErrBusyBuffer        = errors.New(\"busy buffer\")\n\n\t// errBadConnNoWrite is used for connection errors where nothing was sent to the database yet.\n\t// If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn\n\t// to trigger a resend. Use mc.markBadConn(err) to do this.\n\t// See https://github.com/go-sql-driver/mysql/pull/302\n\terrBadConnNoWrite = errors.New(\"bad connection\")\n)\n\nvar defaultLogger = Logger(log.New(os.Stderr, \"[mysql] \", log.Ldate|log.Ltime))\n\n// Logger is used to log critical error messages.\ntype Logger interface {\n\tPrint(v ...any)\n}\n\n// NopLogger is a nop implementation of the Logger interface.\ntype NopLogger struct{}","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/03d76c7e07908e255ce62d126d07ede3f2365d86/errors.go#L12-L48","documentation":"ErrBusyBuffer is returned by the connection's internal write-buffer helpers (buffer.go:106,128,139 — takeBuffer/takeSmallBuffer/takeCompleteBuffer) when b.busy() is true. The buffer can only serve one outstanding write at a time, so this indicates two code paths tried to write on the same connection simultaneously.","triggerScenarios":"Concurrent writes to a single mysqlConn — e.g. sharing one *sql.Conn across goroutines, or a context-cancellation/timeout racing with an in-flight query write inside the driver. It is an internal-level error signalling connection misuse.","commonSituations":"Custom connection wrappers that bypass the pool; calling Exec/Query on a *sql.Conn from multiple goroutines; tight read/write timeouts that cancel a query mid-send while another starts.","solutions":["Use *sql.DB (pooled) instead of a shared single *sql.Conn for concurrent access.","Serialize all operations on any single connection with a mutex if you must hold it.","Avoid setting aggressive per-query write timeouts that can overlap operations on a reused conn.","Treat the connection as bad after this error; discard it rather than reusing."],"exampleFix":"// before: two goroutines share one conn\nc, _ := db.Conn(ctx)\ngo c.ExecContext(ctx, q1) // -> ErrBusyBuffer\ngo c.ExecContext(ctx, q2)\n\n// after: let the pool hand out separate conns\ngo db.ExecContext(ctx, q1)\ngo db.ExecContext(ctx, q2)\n// or if exclusivity is required, guard c with a sync.Mutex","handlingStrategy":"validation","validationCode":"// Never let two goroutines touch one conn. If exclusivity is required,\n// guard it explicitly.\nvar mu sync.Mutex\nmu.Lock(); defer mu.Unlock()\ndb.ExecContext(ctx, q) // serialized","typeGuard":"func isBusyBuffer(err error) bool {\n    return errors.Is(err, mysql.ErrBusyBuffer)\n}","tryCatchPattern":"if errors.Is(err, mysql.ErrBusyBuffer) {\n    // concurrent write on one conn: stop sharing it; use db (pool) or a\n    // mutex, and discard the poisoned conn.\n}","preventionTips":["Prefer *sql.DB over hand-managed single connections for concurrent code.","Serialize any access to a long-lived *sql.Conn.","Avoid overlapping context-cancellation with new ops on a reused conn."],"tags":["concurrency","buffer","internal"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}