Skip to content

Commit

Permalink
Removed shutdown once
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitarheroua committed Dec 17, 2024
1 parent 7ea5ec3 commit a4e07a3
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions engine/access/rest/websockets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"sync"

"github.com/google/uuid"
"github.com/gorilla/websocket"
Expand All @@ -22,7 +21,6 @@ type Controller struct {
communicationChannel chan interface{}
dataProviders *concurrentmap.Map[uuid.UUID, dp.DataProvider]
dataProviderFactory dp.DataProviderFactory
shutdownOnce sync.Once
}

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

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

func (c *Controller) shutdownConnection() {
c.shutdownOnce.Do(func() {
defer func() {
if err := c.conn.Close(); err != nil {
c.logger.Warn().Err(err).Msg("error closing connection")
}
}()

c.logger.Debug().Msg("shutting down connection")
defer func() {
if err := c.conn.Close(); err != nil {
c.logger.Warn().Err(err).Msg("error closing connection")
}
}()

_ = c.dataProviders.ForEach(func(id uuid.UUID, dp dp.DataProvider) error {
err := dp.Close()
c.logger.Error().Err(err).
Str("data_provider", id.String()).
Msg("error closing data provider")
return nil
})
c.logger.Debug().Msg("shutting down connection")

c.dataProviders.Clear()
_ = c.dataProviders.ForEach(func(id uuid.UUID, dp dp.DataProvider) error {
err := dp.Close()
c.logger.Error().Err(err).
Str("data_provider", id.String()).
Msg("error closing data provider")
return nil
})

c.dataProviders.Clear()
}

0 comments on commit a4e07a3

Please sign in to comment.