Skip to content

Commit

Permalink
Merge pull request #752 from gopcua/server-memleakfix
Browse files Browse the repository at this point in the history
Fix subscriptions not purging properly
  • Loading branch information
magiconair authored Dec 3, 2024
2 parents 234d7e9 + 6637344 commit 6499aa1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions server/channel_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ outer:
select {
case <-ctx.Done():
// todo(fs): return error?
if c.logger != nil {
c.logger.Warn("Context done, closing Secure Channel %d", secureChannelID)
}
break outer

default:
Expand All @@ -102,6 +105,11 @@ outer:
c.logger.Warn("Secure Channel %d closed", secureChannelID)
}
break outer
} else if msg.Err != nil {
if c.logger != nil {
c.logger.Error("Secure Channel %d error: %s", secureChannelID, msg.Err)
}
break outer
}
// todo(fs): honor ctx
c.msgChan <- msg
Expand Down
1 change: 1 addition & 0 deletions server/monitored_item_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *MonitoredItemService) DeleteMonitoredItem(id uint32) {
func (s *MonitoredItemService) DeleteSub(id uint32) {
s.Mu.Lock()
items, ok := s.Subs[id]
delete(s.Subs, id)
s.Mu.Unlock()
if !ok {
return
Expand Down
2 changes: 1 addition & 1 deletion server/subscription_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *SubscriptionService) CreateSubscription(sc *uasc.SecureChannel, r ua.Re
s.Mu.Lock()
defer s.Mu.Unlock()

newsubid := uint32(len(s.Subs))
newsubid := uint32(len(s.Subs)) + 1

if s.srv.cfg.logger != nil {
s.srv.cfg.logger.Info("New Sub %d for %v", newsubid, sc.RemoteAddr())
Expand Down

0 comments on commit 6499aa1

Please sign in to comment.