Skip to content
Draft
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
21 changes: 14 additions & 7 deletions graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type (
closed bool
headers http.Header

shutdownGracePeriod time.Duration

initPayload InitPayload
}

Expand Down Expand Up @@ -115,13 +117,14 @@ func (t Websocket) Do(w http.ResponseWriter, r *http.Request, exec graphql.Graph
}

conn := wsConnection{
active: map[string]context.CancelFunc{},
conn: ws,
ctx: r.Context(),
exec: exec,
me: me,
headers: r.Header,
Websocket: t,
active: map[string]context.CancelFunc{},
conn: ws,
ctx: r.Context(),
exec: exec,
me: me,
headers: r.Header,
Websocket: t,
shutdownGracePeriod: 0 * time.Millisecond,
}

if !conn.init() {
Expand Down Expand Up @@ -504,6 +507,10 @@ func (c *wsConnection) close(closeCode int, message string) {
}
c.closed = true
c.mu.Unlock()

if c.shutdownGracePeriod > 0 {
time.Sleep(c.shutdownGracePeriod)
}
_ = c.conn.Close()

if c.CloseFunc != nil {
Expand Down