Commit dadd0c8 1 parent 27e4c8d commit dadd0c8 Copy full SHA for dadd0c8
File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,8 @@ type ws interface {
125
125
}
126
126
127
127
type Websocket struct {
128
- mu sync.RWMutex
128
+ once sync.Once
129
+ mu sync.RWMutex
129
130
// The Fiber.Websocket connection
130
131
Conn * websocket.Conn
131
132
// Define if the connection is alive or not
@@ -564,13 +565,14 @@ func (kws *Websocket) read(ctx context.Context) {
564
565
565
566
// When the connection closes, disconnected method
566
567
func (kws * Websocket ) disconnected (err error ) {
568
+ kws .fireEvent (EventDisconnect , nil , err )
569
+
567
570
// may be called multiple times from different go routines
568
571
if kws .IsAlive () {
569
- kws .setAlive ( false )
570
- if ! kws .IsAlive () {
572
+ kws .once . Do ( func () {
573
+ kws .setAlive ( false )
571
574
close (kws .done )
572
- }
573
- kws .fireEvent (EventDisconnect , nil , err )
575
+ })
574
576
}
575
577
576
578
// Fire error event if the connection is
You can’t perform that action at this time.
0 commit comments