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

websocket clean up resolvers after client abruptly disconnects #1583

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ func (c *wsConnection) init() bool {
}

func (c *wsConnection) write(msg *operationMessage) {
c.mu.Lock()
c.conn.WriteJSON(msg)
c.mu.Unlock()
if msg.Type == "data" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would also ignore keepAlive, connected, and ack messages. I don't think this is what we want

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah @jaredly is right. We cannot afford to miss other types of messages here.

c.mu.Lock()
c.conn.WriteJSON(msg)
c.mu.Unlock()
}
}

func (c *wsConnection) run() {
Expand Down Expand Up @@ -283,12 +285,23 @@ func (c *wsConnection) sendError(id string, errors ...*gqlerror.Error) {
}

func (c *wsConnection) sendConnectionError(format string, args ...interface{}) {
b, err := json.Marshal(&gqlerror.Error{Message: fmt.Sprintf(format, args...)})
if err != nil {
panic(err)
}
for i, _ := range c.active {
select {
case <- c.ctx.Done():
b, err := json.Marshal(&gqlerror.Error{Message: fmt.Sprintf(format, args...)})
if err != nil {
panic(err)
}

c.write(&operationMessage{Type: connectionErrorMsg, Payload: b})
c.write(&operationMessage{Type: connectionErrorMsg, Payload: b})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm the above change makes this a no-op, right? Is there something missing from this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to write same error in loop here?

default:
c.mu.Lock()
closer := c.active[i]
c.mu.Unlock()
c.conn.Close()
closer()
}
}
}

func (c *wsConnection) readOp() *operationMessage {
Expand Down