{"record":{"id":"0fffe5823ae221b9","repo":"ginuerzh/gost","slug":"write-not-supported","errorCode":null,"errorMessage":"write not supported","messagePattern":"write not supported","errorType":"error_code","errorClass":"net.OpError","httpStatus":null,"severity":"error","filePath":"gost.go","lineNumber":163,"sourceCode":"\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\nfunc (c *nopConn) SetDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"nop\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/gost.go#L145-L181","documentation":"nopConn.Write always fails with a *net.OpError whose Err is 'write not supported'. The nop connection is a pure placeholder that performs no I/O, so writes (like reads) are rejected. It exists only to satisfy the net.Conn interface for discarded/placeholder traffic paths.","triggerScenarios":"Any call to Write(b []byte) on a *nopConn, e.g. relaying data toward a connection that was replaced by a nopConn (traffic being discarded, bypassed hop, or test stub).","commonSituations":"io.Copy(dst, src) where dst is a nopConn in a two-way relay; sending responses through a discarded connection; tests writing into the stub.","solutions":["Don't write to nopConn — use it only where traffic should be dropped silently and discard the data yourself (io.Copy(io.Discard, src))","If a writable sink is needed, use io.Discard via an adapter or a net.Pipe() endpoint","Match on the *net.OpError Err ('write not supported') and treat as intentional discard","Change nopConn (if in your fork) to return len(b), nil for silent drop semantics"],"exampleFix":"// before\nio.Copy(nop, src) // errors: write not supported\n// after\nio.Copy(io.Discard, src) // intentionally drop the traffic","handlingStrategy":"type-guard","validationCode":"if _, ok := conn.(*gostNopConn); ok {\n    // discard instead of writing to nopConn\n    io.Copy(io.Discard, src)\n    return nil\n}","typeGuard":"func isNopConn(c net.Conn) bool {\n    return fmt.Sprintf(\"%T\", c) == \"*gost.nopConn\"\n}","tryCatchPattern":"_, err := conn.Write(data)\nif err != nil {\n    var oe *net.OpError\n    if errors.As(err, &oe) && oe.Err.Error() == \"write not supported\" {\n        return len(data), nil // treat as intentional discard\n    }\n    return err\n}","preventionTips":["Route drop-traffic through io.Discard, not nopConn writes","Don't wire nopConn into two-way relay pairs as a destination","Type-check placeholder conns before generic write paths"],"tags":["net-conn","nop","unsupported-operation","discard"],"backgroundTag":"operation-not-supported","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}