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

x/net/websocket: Missing EOF in TLS encrypted websocket connections #2147

Closed
gopherbot opened this issue Aug 11, 2011 · 5 comments
Closed

x/net/websocket: Missing EOF in TLS encrypted websocket connections #2147

gopherbot opened this issue Aug 11, 2011 · 5 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 11, 2011

by nroos@webware-experts.de:

When reading from a TLS encrypted websocket connection with websocket.Read(), and the
connection gets closed, the Read() does not return an error (does not return at all).

What steps will reproduce the problem?
1. Generate a key and certificate:
   openssl req -x509 -nodes -days 365 -subj '/C=US/ST=Oregon/L=Portland/CN=websocket.com' -newkey rsa:1024 -keyout key -out cert

2. Compile the server and client, source code below

3. Run the server

4. Run the client; it opens a websocket connection to the server, after 2 seconds, the
connection gets closed

What is the expected output?

Client should say "Expecting EOF: EOF"

What do you see instead?

"Expecting EOF:"

Which compiler are you using (5g, 6g, 8g, gccgo)?

8g

Which operating system are you using?

Linux (Kubuntu)

Which revision are you using?  (hg identify)

998062d21eea tip

Please provide any additional information below.

--- Server ---

package main

import (
    "fmt"
    "http"
    "websocket"
)

func server(ws *websocket.Conn) {
    fmt.Printf("new connection\n")
    buf := make([]byte, 100)
    for {
        if _, err := ws.Read(buf); err != nil {
            fmt.Printf("%s", err.String())
            break
        }
    }
    fmt.Printf(" => closing connection\n", )
    ws.Close()
}

func main() {
    http.Handle("/websocket", websocket.Handler(server))
    err := http.ListenAndServeTLS(":12345", "cert", "key", nil)
//  err := http.ListenAndServe(":12345", nil)
    if err != nil {
        panic("ListenAndServe: " + err.String())
    }
}

--- Client ---

package main

import (
    "fmt"
    "time"
    "websocket"
)

func main() {
    ws, err := websocket.Dial("wss://localhost:12345/websocket", "", "http://localhost/";)
//  ws, err := websocket.Dial("ws://localhost:12345/websocket", "",
"http://localhost/";)
    if err != nil {
        panic("Dial: " + err.String())
    }
    go readFromServer(ws)
    time.Sleep(2000000000)
    fmt.Printf("Expecting EOF: ")
    ws.Close()
    time.Sleep(60000000000)
}

func readFromServer(ws *websocket.Conn) {
    buf := make([]byte, 1000)
    for {
        if _, err := ws.Read(buf); err != nil {
            fmt.Printf("%s\n", err.String())
            break
        }
    }
}

--- ---

Unencrypted connections work as intended; uncomment the lines in the server and client
to check this
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Aug 18, 2011

Comment 1 by nroos@webware-experts.de:

Tried that on several Linux systems; finally installed a fresh, current Debian in a VM
and used a current Go version (downloaded with "hg clone -u release
https://go.googlecode.com/hg/ go"). The reported problem always occurs.
If anybody wants to have this VM, please contact me. Unfortunately, it's 500MB large.
@rsc
Copy link
Contributor

@rsc rsc commented Aug 18, 2011

Comment 2:

The websocket code is in the middle of being rewritten
to update it for recent protocol changes.  It is possible
that would fix this bug, or at least make it run from
one hiding place to another.
Russ

Status changed to Accepted.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Sep 1, 2011

Comment 3 by nroos@webware-experts.de:

With the new websocket package, the behaviour has become better and worse:
Encrypted websocket connections now deliver an EOF. That's fine.
Unencrypted connections now deliver a "read tcp 127.0.0.1:12345: connection reset by
peer" instead of EOF. In this way, the topic "missing EOF" is still valid...
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Oct 13, 2011

Comment 4 by nroos@webware-experts.de:

I think this issue can be switched to "fixed", it was solved with the rewritten code.
With an almost current version, also the behaviour in my last comment does not seem to
happen any more.
Norbert
@rsc
Copy link
Contributor

@rsc rsc commented Oct 13, 2011

Comment 5:

Thanks for the update.

Status changed to Fixed.

@mikioh mikioh changed the title Missing EOF in TLS encrypted websocket connections websocket: Missing EOF in TLS encrypted websocket connections Jan 14, 2015
@mikioh mikioh added the repo-net label Jan 14, 2015
@mikioh mikioh changed the title websocket: Missing EOF in TLS encrypted websocket connections x/net/websocket: Missing EOF in TLS encrypted websocket connections Jul 30, 2015
@mikioh mikioh modified the milestone: Unreleased Jul 30, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.