gorilla golang websocket.IsUnexpectedCloseError not working correctly under windows?

  go, gorilla, websocket, windows

I have a routine that tries to detect if a websocket error while reading is an UnexpectedCloseError.
This is the code…

having a variable:

myWebsocket                      *websocket.Conn

my method is:

messageType, data, err := myWebsocket.ReadMessage()
if err != nil {
    if websocket.IsUnexpectedCloseError(err) {
        log.Debugf("WebsocketReadDataMessage: unexpected close error: %v", err)
    } else {
        log.Warnf("EXTRANGE!!!!: WebsocketReadDataMessage: error: %v", err)
    }
    return err
}

Running this code under windows sometimes the websocket closes but the call to websocket.IsUnexpectedCloseError returns "false" and I get an error with the text "EXTRANGE!!!!: WebsocketReadDataMessage: error: wsarecv: An existing connection was forcibly closed by the remote host."

Searching for "wsarecv" and I have seen that it is a winsock2 function: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecv

Why IsUnexpectedCloseError doesn’t treat this error as an "UnexpectedCloseError"? Is it a bug or maybe I’m doing something wrong? What can I do to

Source: Windows Questions

LEAVE A COMMENT