Add the ability to fetch all servers, fix cpu usage leak again..

This commit is contained in:
Matthew Penner
2020-04-10 15:39:07 -06:00
parent e719c67e0b
commit 28c8f3f400
11 changed files with 87 additions and 76 deletions

View File

@@ -20,7 +20,7 @@ func getServerWebsocket(c *gin.Context) {
defer handler.Connection.Close()
// Create a context that can be canceled when the user disconnects from this
// socket that will also cancel listeners running in seperate threads.
// socket that will also cancel listeners running in separate threads.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

View File

@@ -13,19 +13,14 @@ func (h *Handler) ListenForExpiration(ctx context.Context) {
// Make a ticker and completion channel that is used to continuously poll the
// JWT stored in the session to send events to the socket when it is expiring.
ticker := time.NewTicker(time.Second * 30)
done := make(chan bool)
// Whenever this function is complete, end the ticker, close out the channel,
// and then close the websocket connection.
defer func() {
ticker.Stop()
done <- true
}()
defer ticker.Stop()
for {
select {
case <-ctx.Done():
case <-done:
return
case <-ticker.C:
{

View File

@@ -194,6 +194,13 @@ func (h *Handler) HandleInbound(m Message) error {
{
token, err := NewTokenPayload([]byte(strings.Join(m.Args, "")))
if err != nil {
// If the error says the JWT expired, send a token expired
// event and hopefully the client renews the token.
if err == jwt.ErrExpValidation {
h.SendJson(&Message{Event: TokenExpiredEvent})
return nil
}
return err
}