Skip to content

Commit a4e07a3

Browse files
committed
Removed shutdown once
1 parent 7ea5ec3 commit a4e07a3

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

engine/access/rest/websockets/controller.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"sync"
87

98
"github.com/google/uuid"
109
"github.com/gorilla/websocket"
@@ -22,7 +21,6 @@ type Controller struct {
2221
communicationChannel chan interface{}
2322
dataProviders *concurrentmap.Map[uuid.UUID, dp.DataProvider]
2423
dataProviderFactory dp.DataProviderFactory
25-
shutdownOnce sync.Once
2624
}
2725

2826
func NewWebSocketController(
@@ -38,7 +36,6 @@ func NewWebSocketController(
3836
communicationChannel: make(chan interface{}), //TODO: should it be buffered chan?
3937
dataProviders: concurrentmap.New[uuid.UUID, dp.DataProvider](),
4038
dataProviderFactory: dataProviderFactory,
41-
shutdownOnce: sync.Once{},
4239
}
4340
}
4441

@@ -228,23 +225,21 @@ func (c *Controller) handleListSubscriptions(ctx context.Context, msg models.Lis
228225
}
229226

230227
func (c *Controller) shutdownConnection() {
231-
c.shutdownOnce.Do(func() {
232-
defer func() {
233-
if err := c.conn.Close(); err != nil {
234-
c.logger.Warn().Err(err).Msg("error closing connection")
235-
}
236-
}()
237-
238-
c.logger.Debug().Msg("shutting down connection")
228+
defer func() {
229+
if err := c.conn.Close(); err != nil {
230+
c.logger.Warn().Err(err).Msg("error closing connection")
231+
}
232+
}()
239233

240-
_ = c.dataProviders.ForEach(func(id uuid.UUID, dp dp.DataProvider) error {
241-
err := dp.Close()
242-
c.logger.Error().Err(err).
243-
Str("data_provider", id.String()).
244-
Msg("error closing data provider")
245-
return nil
246-
})
234+
c.logger.Debug().Msg("shutting down connection")
247235

248-
c.dataProviders.Clear()
236+
_ = c.dataProviders.ForEach(func(id uuid.UUID, dp dp.DataProvider) error {
237+
err := dp.Close()
238+
c.logger.Error().Err(err).
239+
Str("data_provider", id.String()).
240+
Msg("error closing data provider")
241+
return nil
249242
})
243+
244+
c.dataProviders.Clear()
250245
}

0 commit comments

Comments
 (0)