{"id":"b62c9bf845239df9","repo":"go-redis/redis","slug":"redis-can-t-peek-reply-type-no-data-available","errorCode":null,"errorMessage":"redis: can't peek reply type, no data available","messagePattern":"redis: can't peek reply type, no data available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pool/conn.go","lineNumber":999,"sourceCode":"\n// HasBufferedData safely checks if the connection has buffered data.\n// This method is used to avoid data races when checking for push notifications.\nfunc (cn *Conn) HasBufferedData() bool {\n\t// Use read lock for concurrent access to reader state\n\tcn.readerMu.RLock()\n\tdefer cn.readerMu.RUnlock()\n\treturn cn.rd.Buffered() > 0\n}\n\n// PeekReplyTypeSafe safely peeks at the reply type.\n// This method is used to avoid data races when checking for push notifications.\nfunc (cn *Conn) PeekReplyTypeSafe() (byte, error) {\n\t// Use read lock for concurrent access to reader state\n\tcn.readerMu.RLock()\n\tdefer cn.readerMu.RUnlock()\n\n\tif cn.rd.Buffered() <= 0 {\n\t\treturn 0, fmt.Errorf(\"redis: can't peek reply type, no data available\")\n\t}\n\treturn cn.rd.PeekReplyType()\n}\n\n// PeekReplyTypeForCheck peeks at the reply type while holding readerMu, so it is\n// safe against a concurrent SetNetConn resetting the reader during handoff.\n// Unlike PeekReplyTypeSafe it does not require the data to already be buffered:\n// the pool health check calls it after connCheck reports unexpected socket data,\n// and connCheck only MSG_PEEKs, so the byte still has to be pulled from the\n// socket into the reader here.\nfunc (cn *Conn) PeekReplyTypeForCheck() (byte, error) {\n\tcn.readerMu.RLock()\n\tdefer cn.readerMu.RUnlock()\n\treturn cn.rd.PeekReplyType()\n}\n\nfunc (cn *Conn) Write(b []byte) (int, error) {\n\t// Lock-free netConn access for better performance","sourceCodeStart":981,"sourceCodeEnd":1017,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/internal/pool/conn.go#L981-L1017","documentation":"Error \"redis: can't peek reply type, no data available\" thrown in go-redis/redis.","triggerScenarios":"Thrown at internal/pool/conn.go:999 when the library encounters an invalid state.","commonSituations":"Pair every peek with a preceding write of a command expecting a reply.","solutions":["Ensure the server response has fully arrived before peeking (check read deadlines/buffering)","Do not peek on a connection with no pending reply"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}