meteor / meteor

Meteor, the JavaScript App Platform

Home Page:https://meteor.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception in onStop callback: TypeError: handle.stop is not a function

perbergland opened this issue · comments

With Meteor 3 beta 4 and the small example app (the react skeleton app in meteor), I get this error when the web page is closed and the subscription is stopped.

I20240225-16:05:53.868(1)? Exception in onStop callback: TypeError: handle.stop is not a function
I20240225-16:05:53.878(1)?     at OplogObserveDriver._stop (packages/mongo/oplog_observe_driver.js:966:20)
I20240225-16:05:53.878(1)?     at OplogObserveDriver.stop (packages/mongo/oplog_observe_driver.js:971:12)
I20240225-16:05:53.878(1)?     at ObserveMultiplexer._stop (packages/mongo/observe_multiplex.js:85:5)
I20240225-16:05:53.878(1)?     at ObserveMultiplexer.removeHandle (packages/mongo/observe_multiplex.js:72:7)
I20240225-16:05:53.878(1)?     at ObserveHandle.stop (packages/mongo/observe_multiplex.js:230:5)
I20240225-16:05:53.878(1)?     at Subscription.<anonymous> (packages/mongo/collection.js:590:14)
I20240225-16:05:53.878(1)?     at Subscription.<anonymous> (packages/meteor.js:1400:19)

Repro:
Clone https://github.com/Meteor-Community-Packages/meteor-typescript/tree/meteor3/tests/small-typescript-app (the meteor3 branch) and run meteor run. Open localhost:3000 and then close the browser tab to see the error.

macos sonoma 14.3.1, MBP M1

I found the root cause, which is that the following line of code needs to be converted to async since onOplogEntry is async:

_oplogHandle.onOplogEntry

_onOplogEntry

This is hard to fix since forEachTrigger will need to become async and it is invoked in the OplogObserveDriver constructor but constructors cannot be async.

To fix this, the async code should be moved to an async _init method

if (observeDriver._init) {

but it doesn’t end there - there is a whole slew of calls to async code without appropriate awaits in PollingObserveDriver and OplogObserveDriver and many of these calls are in the constructors

Moved stuff from the two constructors into the async _init method and that fixed the immediate bug