I just got the following exception in my integration tests:
TypeError: this.keepAliveHandle.unref is not a function
at ConnectionPool.Object.<anonymous>.ConnectionPool.open (node_modules/@google-cloud/pubsub/src/connection-pool.js:444:26)
at new ConnectionPool (node_modules/@google-cloud/pubsub/src/connection-pool.js:87:8)
at Subscription.Object.<anonymous>.Subscriber.openConnection_ (node_modules/@google-cloud/pubsub/src/subscriber.js:445:37)
at Subscription.<anonymous> (node_modules/@google-cloud/pubsub/src/subscriber.js:362:14)
at client.topic.createSubscription.then.then.subscription (node_modules/@karmalicious/nodejs-drivers/build/drivers/pub-sub/index.js:39:26)
I tried to remove the row that threw the error, and nothing crashes. I can publish and subscribe to pubsub as expected.
I opened a PR to help the discussion: https://github.com/googleapis/nodejs-pubsub/pull/242
Looking at the code, the this.keepAliveHandle.unref() call doesn't make sense to me as the code will be 15.unref() (or some other number) at runtime.
@google-cloud/pubsub version: 0.19.0_So sorry, I won't be able to reproduce this right now._
Any progress on this?
Node's setInterval returns a Timeout instance, which defines unref: https://nodejs.org/api/timers.html#timers_timeout_unref. If setInterval is returning a plain number instead of a Timeout instance, perhaps there's some other code that is overriding setInterval (this seems particularly likely if you're using a mocking library in your tests)?
@ide All the love to you! We have removed our integration code right now, but it explains why our tests failed when it seemed to work well in our development environment.
To reproduce this issue outside of pubsub, just write a test in jest where you call unref(), and it will fail. I'm so happy to finally close this issue after spending lots time trying to reproduce the error.
_(You should set jest to testEnvironment: 'node', which our integration test config did not have, but our unit tests had.)_
Most helpful comment
_(You should set jest to
testEnvironment: 'node', which our integration test config did not have, but our unit tests had.)_