Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property '_$onMessage' of undefined #167

Closed
ronag opened this issue Jun 30, 2016 · 6 comments · Fixed by #188
Closed

Cannot read property '_$onMessage' of undefined #167

ronag opened this issue Jun 30, 2016 · 6 comments · Fixed by #188
Assignees
Labels

Comments

@ronag
Copy link

ronag commented Jun 30, 2016

/deepstream.io-client-js/src/record/record-handler.js:276
    var onMessage = this._records[ recordName ]._$onMessage.bind( this._records[ recordName ] );
                                               ^

TypeError: Cannot read property '_$onMessage' of undefined
    at RecordHandler._onDestroyPending (foo/node_modules/deepstream.io-client-js/src/record/record-handler.js:276:45)
    at Emitter.emit (foo/node_modules/component-emitter/index.js:134:20)
    at .<anonymous> (foo/node_modules/deepstream.io-client-js/src/record/record.js:236:9)
    at on (foo/node_modules/component-emitter/index.js:66:8)
    at Emitter.emit (foo/node_modules/component-emitter/index.js:134:20)
    at Record._setReady (foo/node_modules/deepstream.io-client-js/src/record/record.js:455:7)
    at Record._onRead (foo/node_modules/deepstream.io-client-js/src/record/record.js:439:7)
    at Record._$onMessage (foo/node_modules/deepstream.io-client-js/src/record/record.js:289:9)
    at RecordHandler._$handle (foo/node_modules/deepstream.io-client-js/src/record/record-handler.js:228:25)
    at Client._$onMessage (foo/node_modules/deepstream.io-client-js/src/client.js:130:42)
@ronag ronag changed the title _onMessage of undefined Cannot read property '_$onMessage' of undefined Jun 30, 2016
@yasserf yasserf added the bug label Jun 30, 2016
@ronag
Copy link
Author

ronag commented Jul 1, 2016

Seems to happen during reconnection:

16:13:51.368Z  INFO foo:  (connectionState=ERROR)
16:13:51.369Z  INFO foo: Deepstream Connection State Changed. (connectionState=RECONNECTING)
16:13:51.369Z  INFO foo:  (connectionState=RECONNECTING)
16:13:51.371Z  INFO foo: Deepstream Error. (event=connectionError, topic=null)
  error: Can't connect! Deepstream server unreachable on 0.0.0.0:6021
16:13:55.375Z  INFO foo: Deepstream Connection State Changed. (connectionState=AWAITING_CONNECTION)
16:13:55.375Z  INFO foo:  (connectionState=AWAITING_CONNECTION)
16:13:55.376Z  INFO foo: Deepstream Connection State Changed. (connectionState=AWAITING_AUTHENTICATION)
16:13:55.376Z  INFO foo:  (connectionState=AWAITING_AUTHENTICATION)
16:13:55.376Z  INFO foo: Deepstream Connection State Changed. (connectionState=AUTHENTICATING)
16:13:55.376Z  INFO foo:  (connectionState=AUTHENTICATING)
16:13:55.377Z  INFO foo: Deepstream Connection State Changed. (connectionState=OPEN)
16:13:55.377Z  INFO foo:  (connectionState=OPEN)
16:13:55.505Z  INFO foo:  (key=search/simple?{"query":"","count":128}, isSubscribed=true)
16:13:55.506Z  INFO foo:  (key=search/simple?{"query":"","count":256}, isSubscribed=true)
foo/node_modules/deepstream.io-client-js/src/record/record-handler.js:276
    var onMessage = this._records[ recordName ]._$onMessage.bind( this._records[ recordName ] );
                                               ^

TypeError: Cannot read property '_$onMessage' of undefined
    at RecordHandler._onDestroyPending (foo/node_modules/deepstream.io-client-js/src/record/record-handler.js:276:45)
    at Emitter.emit (foo/node_modules/component-emitter/index.js:134:20)
    at .<anonymous> (foo/node_modules/deepstream.io-client-js/src/record/record.js:236:9)
    at on (foo/node_modules/component-emitter/index.js:66:8)
    at Emitter.emit (foo/node_modules/component-emitter/index.js:134:20)
    at Record._setReady (foo/node_modules/deepstream.io-client-js/src/record/record.js:455:7)
    at Record._onRead (foo/node_modules/deepstream.io-client-js/src/record/record.js:439:7)
    at Record._$onMessage (foo/node_modules/deepstream.io-client-js/src/record/record.js:289:9)
    at RecordHandler._$handle (foo/node_modules/deepstream.io-client-js/src/record/record-handler.js:228:25)
    at Client._$onMessage (foo/node_modules/deepstream.io-client-js/src/client.js:130:42)

@ronag
Copy link
Author

ronag commented Jul 13, 2016

Here is a reproducible example:

import deepstream from 'deepstream.io-client-js'

const ds = deepstream('0.0.0.0:6021')
  .login({}, (success, authData) => {
    if (!success) {
      console.log({ authData }, 'Deepstream Authentication Failed. Shutting down...')
      setTimeout(() => process.exit(1), 500)
    }
  })

ds.on('connectionStateChanged', connectionState => {
  console.log({ connectionState }, 'Deepstream Connection State Changed.')
})

ds.on('error', (error, event, topic) => {
  console.log({ error, event, topic }, 'Deepstream Error.')
})

setInterval(() => {
  for (let n = 0; n < 8; ++n) {
    updateRecord()
  }
}, 500)

let x = 0
function updateRecord () {
  const record = ds.record.getRecord('test/1')
  record.set({ x })
  record.discard()
  x++
}
{ connectionState: 'OPEN' } 'Deepstream Connection State Changed.'
/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record-handler.js:276
    var onMessage = this._records[ recordName ]._$onMessage.bind( this._records[ recordName ] );
                                               ^

TypeError: Cannot read property '_$onMessage' of undefined
    at RecordHandler._onDestroyPending (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record-handler.js:276:45)
    at Emitter.emit (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/component-emitter/index.js:134:20)
    at .<anonymous> (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record.js:233:9)
    at on (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/component-emitter/index.js:66:8)
    at Emitter.emit (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/component-emitter/index.js:134:20)
    at Record._setReady (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record.js:452:7)
    at Record._onRead (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record.js:436:7)
    at Record._$onMessage (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record.js:286:9)
    at RecordHandler._$handle (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/record/record-handler.js:228:25)
    at Client._$onMessage (/Users/ronagy/Projects/GitHub/public/ds-playground/node_modules/deepstream.io-client-js/src/client.js:128:42)

@yasserf
Copy link
Contributor

yasserf commented Jul 13, 2016

Great, thank you!

@yasserf yasserf added the ready label Jul 19, 2016
@timaschew timaschew self-assigned this Jul 20, 2016
@ronag
Copy link
Author

ronag commented Jul 26, 2016

Any progress on this issue? It's starting to become a bit more urgent for us...

@yasserf
Copy link
Contributor

yasserf commented Jul 26, 2016

We got this issue and the other two you just commented on put in for the next release, aiming for friday/monday.

timaschew added a commit that referenced this issue Jul 26, 2016
timaschew added a commit that referenced this issue Jul 26, 2016
@timaschew
Copy link
Contributor

timaschew commented Jul 26, 2016

The issue it's fixed in a branch, missing some tests.
For now you can use a more defensive implementation to avoid the issue:

'use strict'
const deepstream = require('.')
const Promise = require('bluebird')

const ds = deepstream('0.0.0.0:6021')
  .login({}, (success, authData) => {
    if (!success) {
      console.log({ authData }, 'Deepstream Authentication Failed. Shutting down...')
      setTimeout(() => process.exit(1), 500)
    }
  })

ds.on('connectionStateChanged', connectionState => {
  console.log({ connectionState }, 'Deepstream Connection State Changed.')
})

ds.on('error', (error, event, topic) => {
  console.log({ error, event, topic }, 'Deepstream Error.')
})

setInterval(Promise.coroutine(function*() {
  for (let n = 0; n < 8; ++n) {
    yield updateRecord()
  }
}), 500)

let x = 0
function updateRecord () {
  console.log(x)
  return new Promise((resolve, reject) => {
    const record = ds.record.getRecord('test/1')
    record.set({ x: x++ })
    record.on( 'discard', () => {
      resolve()
    })
    record.discard()
  })
}

If you want to do the same with record.delete() you need the defensive way anyway (you need to listen to the deleted event).

ronag pushed a commit to nxtedition/deepstream.io-client-js that referenced this issue Jul 26, 2016
@yasserf yasserf added in progress and removed ready labels Jul 27, 2016
yasserf pushed a commit that referenced this issue Jul 28, 2016
yasserf added a commit that referenced this issue Jul 28, 2016
Bug/#167 multiple discards of the same record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants