-
Notifications
You must be signed in to change notification settings - Fork 18k
net: problem with Close and final packet delivery #3746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
Here is even simpler program to demonstrate your issue: package rpc import ( "net/http" "net" "testing" ) func TestALEX(t *testing.T) { arith := new(Arith) Register(arith) HandleHTTP() l, e := net.Listen("tcp", "127.0.0.1:0") if e != nil { t.Fatalf("listen error: %v", e) } defer l.Close() go http.Serve(l, nil) client, err := DialHTTP("tcp", l.Addr().String()) if err != nil { t.Fatalf("dialing: %v", err) } defer client.Close() args := Args{17, 8} var reply Reply err = client.Call("Arith.Mul", args, &reply) if err != nil { t.Fatal("arith error:", err) } t.Logf("Arith: %d*%d=%d\n", args.A, args.B, reply) } I think the problem here is, we do not use tcp as intended. Here is pure net test to demonstrate what is happening: package net import ( "io" "testing" "time" ) func TestALEX(t *testing.T) { l, e := Listen("tcp", "127.0.0.1:0") if e != nil { t.Fatal(e) } defer l.Close() read := func(r io.Reader) (byte, error) { var m [1]byte _, e = io.ReadFull(r, m[:]) return m[0], e } write := func(w io.Writer, m byte) { _, e = w.Write([]byte{m}) if e != nil { t.Fatal(e) } } ch := make(chan error) go func() { c, e := l.Accept() if e != nil { t.Fatal(e) } defer c.Close() for e == nil { _, e = read(c) } ch <- e }() c, err := Dial("tcp", l.Addr().String()) if err != nil { t.Fatal(e) } write(c, 'A') go read(c) time.Sleep(10 * time.Millisecond) c.Close() e = <-ch if e != nil && e != io.EOF { t.Fatal(e) } } This test fails because tcp connection is reset by c.Close. We should really use c.(*TCPConn).CloseWrite() instead. But we do not. In net/rpc and in net/http/fcgi (https://golang.org/issue/3710) we assume that tcp connection can just be closed and final bits of conversation will reach their destination reliably. But here we see connection is reset, so tcp peers are out of sync and confused. We could change our windows network code to ignore these read errors - rewrite this error code into io.EOF, but I am not sure if this is always appropriate. This suggestion will not help when we hurt other programs, like in https://golang.org/issue/3710. I am not sure what to do. Alex Status changed to Accepted. |
Comment 3 by support@ryron.org: and can not connect to other device. both writing by golang |
http://golang.org/cl/6604072 Owner changed to @alexbrainman. Status changed to Started. |
This issue was closed by revision fa3e4fc. Status changed to Fixed. |
I've done a same tutorial he did. but the problem is not fixed, yet. You can see the RPC tutorial here. http://jan.newmarch.name/go/rpc/chapter-rpc.html I had exactly a same error as he'd written before. rpc: rpc: server cannot decode request: WSARecv tcp 127.0.0.1:1234: The specified network name is no longer available. Attachments:
|
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by feixings:
Attachments:
The text was updated successfully, but these errors were encountered: