Skip to content
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

net: windows error messages are confusing #4320

Closed
alexbrainman opened this issue Oct 31, 2012 · 1 comment

Comments

Projects
None yet
3 participants
@alexbrainman
Copy link
Member

commented Oct 31, 2012

This program:

package main

import (
    "fmt"
    "log"
    "net"
    "time"
)

func timeout() {
    ln, err := net.Listen("tcp", "127.0.0.1:0")
    if err != nil {
        log.Fatalf("ListenTCP on :0: %v", err)
    }

    quit := make(chan bool)

    go func() {
        c, err := ln.Accept()
        if err != nil {
            log.Fatalf("Accept: %v", err)
        }
        defer c.Close()
        quit <- true
    }()

    c, err := net.Dial("tcp", ln.Addr().String())
    if err != nil {
        log.Fatalf("Dial: %v", err)
    }
    defer c.Close()

    err = c.SetReadDeadline(time.Now().Add(time.Second))
    if err != nil {
        log.Fatalf("SetReadDeadline: %v", err)
    }
    var buf [10]byte
    _, err = c.Read(buf[:])
    if err == nil {
        log.Fatalf("Read should not succeed")
    }
    fmt.Printf("ERROR is %v\n", err)

    <-quit
}

func close() {
    ln, err := net.Listen("tcp", "127.0.0.1:0")
    if err != nil {
        log.Fatalf("ListenTCP on :0: %v", err)
    }

    quit := make(chan bool)

    go func() {
        c, err := ln.Accept()
        if err != nil {
            log.Fatalf("Accept: %v", err)
        }
        defer c.Close()
        quit <- true
    }()

    c, err := net.Dial("tcp", ln.Addr().String())
    if err != nil {
        log.Fatalf("Dial: %v", err)
    }
    defer c.Close()

    go func() {
        time.Sleep(time.Second)
        c.Close()
    }()

    var buf [10]byte
    _, err = c.Read(buf[:])
    if err == nil {
        log.Fatalf("Read should not succeed")
    }
    fmt.Printf("ERROR is %v\n", err)

    <-quit
}

func main() {
    timeout()
    close()
}

displays

ERROR is read tcp 127.0.0.1:50197: i/o timeout                     
ERROR is read tcp 127.0.0.1:50866: use of closed network connection

on linux and

ERROR is WSARecv tcp 127.0.0.1:3084: resource temporarily unavailable
ERROR is WSARecv tcp 127.0.0.1:3088: resource temporarily unavailable

on windows. I think windows error messages are confusing.

Alex
@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Nov 2, 2012

Comment 1:

This issue was closed by revision 84e2046.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015

@rsc rsc removed the go1.1 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.