Skip to content

Commit

Permalink
feat: add logs for unsubscribe on connection close
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru committed May 21, 2024
1 parent 741bbe6 commit fa2dc46
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions coap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ func handleGet(m *mux.Message, w mux.ResponseWriter, msg *messaging.Message, key
if obs == startObserve {
c := coap.NewClient(w.Conn(), m.Token(), logger)
w.Conn().AddOnClose(func() {
if err := service.Unsubscribe(context.Background(), key, msg.GetChannel(), msg.GetSubtopic(), c.Token()); err != nil {
logger.Warn(fmt.Sprintf("Error unsubscribing: %s", err))
err := service.Unsubscribe(context.Background(), key, msg.GetChannel(), msg.GetSubtopic(), c.Token())
args := []any{
slog.String("channel_id", msg.GetChannel()),
slog.String("subtopic", msg.GetSubtopic()),
slog.String("token", c.Token()),
}
if err != nil {
args = append(args, slog.Any("error", err))
logger.Warn("Unsubscribe idle client failed to complete successfully ", args...)
return
}
logger.Warn("Unsubscribe idle client completed successfully", args...)
})
return service.Subscribe(w.Conn().Context(), key, msg.GetChannel(), msg.GetSubtopic(), c)
}
Expand Down

0 comments on commit fa2dc46

Please sign in to comment.