From 21ab51bde7a32d179101254a61302333abc02c2d Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sun, 30 Sep 2018 16:46:10 +0300 Subject: [PATCH] fix https://github.com/kataras/iris/issues/1087 Former-commit-id: 5f55201d9f494efd3f2f4d92231ad8f271ce94e6 --- websocket/connection.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/websocket/connection.go b/websocket/connection.go index 748f8067..4d1ec8ab 100644 --- a/websocket/connection.go +++ b/websocket/connection.go @@ -2,6 +2,7 @@ package websocket import ( "bytes" + "errors" "io" "net" "strconv" @@ -580,7 +581,14 @@ func (c *connection) Wait() { c.startReader() } +// ErrAlreadyDisconnected can be reported on the `Connection#Disconnect` function whenever the caller tries to close the +// connection when it is already closed by the client or the caller previously. +var ErrAlreadyDisconnected = errors.New("already disconnected") + func (c *connection) Disconnect() error { + if c == nil || c.disconnected { + return ErrAlreadyDisconnected + } return c.server.Disconnect(c.ID()) }