{"id":"318994faa1131432","repo":"go-redis/redis","slug":"redis-no-initconnfunc-set-for-conn-d","errorCode":null,"errorMessage":"redis: no initConnFunc set for conn[%d]","messagePattern":"redis: no initConnFunc set for conn\\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pool/conn.go","lineNumber":693,"sourceCode":"}\n\n// SetOnCscReinit sets the client-side-caching pre-reinitialization hook,\n// overwriting any previous one.\nfunc (cn *Conn) SetOnCscReinit(fn func()) {\n\tcn.onCscReinit = fn\n}\n\n// SetInitConnFunc sets the connection initialization function to be called on reconnections.\nfunc (cn *Conn) SetInitConnFunc(fn func(context.Context, *Conn) error) {\n\tcn.initConnFunc = fn\n}\n\n// ExecuteInitConn runs the stored connection initialization function if available.\nfunc (cn *Conn) ExecuteInitConn(ctx context.Context) error {\n\tif cn.initConnFunc != nil {\n\t\treturn cn.initConnFunc(ctx, cn)\n\t}\n\treturn fmt.Errorf(\"redis: no initConnFunc set for conn[%d]\", cn.GetID())\n}\n\nfunc (cn *Conn) SetNetConn(netConn net.Conn) {\n\t// Store the new connection atomically first (lock-free)\n\tcn.setNetConn(netConn)\n\t// Protect reader reset operations to avoid data races\n\t// Use write lock since we're modifying the reader state\n\tcn.readerMu.Lock()\n\tcn.rd.Reset(netConn)\n\tcn.readerMu.Unlock()\n\n\tcn.bw.Reset(netConn)\n\n\t// A new socket is a new server session with no HIMPORT fieldsets and\n\t// nothing left to discard.\n\tcn.ClearPreparedFieldsets(0)\n}\n","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/internal/pool/conn.go#L675-L711","documentation":"Error \"redis: no initConnFunc set for conn[%d]\" thrown in go-redis/redis.","triggerScenarios":"Thrown at internal/pool/conn.go:693 when the library encounters an invalid state.","commonSituations":"Never construct pool connections outside the pool factory.","solutions":["Construct connections through the pool's NewConnPool so initConnFunc is wired","If constructing pool.Conn manually, set the init function before first use"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}