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 error check #3727

Closed
gopherbot opened this issue Jun 12, 2012 · 2 comments
Closed

x/net/websocket: missing error check #3727

gopherbot opened this issue Jun 12, 2012 · 2 comments

Comments

@gopherbot
Copy link

by svinartchouk.alexis@free.fr:

There is something strange in the Send function (lines 287 to 301 in
websocket/websocket.go):

On the line 297 we have this:
w, err := ws.frameWriterFactory.NewFrameWriter(payloadType)
And on the next line, instead of checking the error, we directly write to w:
_, err = w.Write(data)
But if there was an error, w is nil and calling w.Write(data) leads to a runtime
exception.
Also, at the very beginning of the function, there is a check for the err variable which
have not been affected at this point.

Here is my corrected version:

func (cd Codec) Send(ws *Conn, v interface{}) (err error) {
    data, payloadType, err := cd.Marshal(v)
    if err != nil {
        return err
    }
    ws.wio.Lock()
    defer ws.wio.Unlock()
    w, err := ws.frameWriterFactory.NewFrameWriter(payloadType)
    if err != nil {
        return err
    }
    _, err = w.Write(data)
    w.Close()
    return err
}

Thanks
@rsc
Copy link
Contributor

rsc commented Jun 13, 2012

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@adg
Copy link
Contributor

adg commented Jun 18, 2012

Comment 2:

This issue was closed by revision golang/net@675d40b.

Status changed to Fixed.

@mikioh mikioh changed the title websocket: missing error check x/net/websocket: missing error check 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
Development

No branches or pull requests

4 participants