Monti APM (Meteor 3): unguarded session.id in pubsub tracking crashes on mid-publish disconnects

Hi @zodern

flagging a small-but-live Meteor 3 bug in montiapm:agent that’s worth a quick patch release, since it affects any Meteor 3 app running Monti in production.

Symptom (production):

TypeError: Cannot read properties of null (reading 'id')
     at PubsubModel._trackReady (montiapm:agent/lib/models/pubsub.js:89)
     at Subscription.<anonymous> (montiapm:agent/lib/hijack/wrap_subscription.js:46)
     at Subscription.ready (ddp-server/livedata_server.js:1008)

It fires as an unhandledRejection, so it doesn’t crash the process, but it lands as a status:error in APM/DataDog and pollutes error monitoring.

Root cause: when a client disconnects during an async publish (a publication returning a cursor), Meteor 3’s Subscription._deactivate() nulls this._session for GC. Meteor’s own Subscription.ready()/error() guard against this via _isDeactivated(), but the agent’s ready/error/_deactivate wrappers run their tracking first and pass this._session (now null) into _track*, which dereferences session.id.

On current master, _trackReady, _trackUnsub, and _trackError all deref session.id unguarded. This is the same class you fixed for _trackError in 01fc40a12 (#149) with session?.id — but that guard only covered _trackError and isn’t on master. The same one-liner (session?.id), or a this._session check in wrap_subscription.js before the _track* calls, would cover the ready/unsub paths too. That commit even has a disabled test noting the Meteor 3 “async error after stop” gap, which is the same case.

Full write-up + suggested fix here: Issue · GitHub — happy to open a PR if that speeds it up.

It’s a tiny change with broad reach for Meteor 3 users, so a quick patch release would be much appreciated