{"record":{"id":"52089db9cde151b0","repo":"ginuerzh/gost","slug":"read-not-supported","errorCode":null,"errorMessage":"read not supported","messagePattern":"read not supported","errorType":"error_code","errorClass":"net.OpError","httpStatus":null,"severity":"error","filePath":"gost.go","lineNumber":159,"sourceCode":"\tw io.Writer\n}\n\nfunc (rw *readWriter) Read(p []byte) (n int, err error) {\n\treturn rw.r.Read(p)\n}\n\nfunc (rw *readWriter) Write(p []byte) (n int, err error) {\n\treturn rw.w.Write(p)\n}\n\nvar nopClientConn = &nopConn{}\n\n// a nop connection implements net.Conn,\n// it does nothing.\ntype nopConn struct{}\n\nfunc (c *nopConn) Read(b []byte) (n int, err error) {\n\treturn 0, &net.OpError{Op: \"read\", Net: \"nop\", Source: nil, Addr: nil, Err: errors.New(\"read not supported\")}\n}\n\nfunc (c *nopConn) Write(b []byte) (n int, err error) {\n\treturn 0, &net.OpError{Op: \"write\", Net: \"nop\", Source: nil, Addr: nil, Err: errors.New(\"write not supported\")}\n}\n\nfunc (c *nopConn) Close() error {\n\treturn nil\n}\n\nfunc (c *nopConn) LocalAddr() net.Addr {\n\treturn nil\n}\n\nfunc (c *nopConn) RemoteAddr() net.Addr {\n\treturn nil\n}\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/gost.go#L141-L177","documentation":"nopConn is a do-nothing net.Conn (a sink/discarded connection); its Read always fails with a *net.OpError whose Err is 'read not supported'. The library throws this because a nop connection has no peer and no data stream — reading from it is meaningless. It exists so code that requires a net.Conn can be handed a harmless placeholder.","triggerScenarios":"Any call to Read(b []byte) on a value of type *nopConn, e.g. when code copies/relays from a connection that was substituted with a nopConn (bypass node, discarded traffic, testing placeholder).","commonSituations":"io.Copy from a nopConn in a relay pair; generic code that assumes every net.Conn is readable; tests that accidentally wire the nop connection into a data path.","solutions":["Don't read from nopConn — it is write/discarded-traffic only; restructure so no Read is attempted","If you need a readable placeholder, substitute a net.Pipe() connection or an empty reader wrapped appropriately","Check the *net.OpError's Err message ('read not supported') and skip reads for nop connections","If you own the code, implement Read to return io.EOF instead of an error if silent termination is desired"],"exampleFix":"// before\nio.Copy(dst, nop) // always errors: read not supported\n// after\nif _, ok := conn.(*gost.NopConn); ok {\n  // nothing to relay from a nop connection\n  return nil\n}\nio.Copy(dst, conn)","handlingStrategy":"type-guard","validationCode":"if _, ok := conn.(*gostNopConn); ok {\n    // nop connection is not readable; skip the read path\n    return nil\n}","typeGuard":"func isNopConn(c net.Conn) bool {\n    return fmt.Sprintf(\"%T\", c) == \"*gost.nopConn\"\n}","tryCatchPattern":"n, err := conn.Read(buf)\nif err != nil {\n    var oe *net.OpError\n    if errors.As(err, &oe) && oe.Err.Error() == \"read not supported\" {\n        return nil // expected for nop connections\n    }\n    return err\n}","preventionTips":["Only use nopConn where traffic is intentionally discarded","Never pass nopConn into io.Copy or relay loops as a source","Prefer net.Pipe() endpoints when a readable stub is needed"],"tags":["net-conn","nop","unsupported-operation","relay"],"backgroundTag":"operation-not-supported","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}