deepstreamIO / deepstream.io

deepstream.io server
https://deepstreamio.github.io
MIT License
7.13k stars 382 forks source link

TypeError: this.services.storage.whenReady is not a function when using mongodb storage #1122

Closed jazz7381 closed 1 year ago

jazz7381 commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. install npm @deepstream/server
  2. install deepstream.io-storage-mongodb
  3. Start npm

Expected behavior run normaly

Server version "@deepstream/server": "^6.2.1", "deepstream.io-storage-mongodb": "^1.1.1"

Server OS Ubuntu 20 WSL

Node version 14

Server config

# General
# Each server within a cluster needs a unique name. Set to UUID to have deepstream autogenerate a unique id
serverName: UUID
# Show the deepstream logo on startup
showLogo: true
# Plugin startup timeout – deepstream init will fail if any plugins fail to emit a 'done' event within this timeout
dependencyInitializationTimeout: 5000
# Directory where all plugins reside
#libDir: ../lib
# Exit the process a fatal error occurs, like losing a cache connection
exitOnFatalError: false
# Log messages with this level and above. Valid levels are DEBUG, INFO, WARN, ERROR, OFF
logLevel: INFO

# This disables specific feature in DS, which is a more performant way
# than disabling via permissions and is also how telemetry figures out
# what features are enabled
enabledFeatures:
  record: true
  event: true
  rpc: true
  presence: true

telemetry:
  type: deepstreamIO
  options:
    # Disable telemetry entirely
    enabled: false
    # Prints whatever will be sent to the telemetry endpoint,
    # without actually sending it
    debug: false
    # An anonymous uuid that allows us to know its one unique
    # deployment. Please don't generate these randomly if using
    # node, it really skews up analytics.
    # deploymentId: <uuid goes here>

rpc:
  # Timeout for client RPC acknowledgement
  ackTimeout: 1000
  # Timeout for actual RPC provider response
  responseTimeout: 10000
  # Don't send requestorName by default.
  provideRequestorName: false
  # Don't send requestorData by default.
  provideRequestorData: false

record:
  # Maximum time permitted to fetch from cache
  cacheRetrievalTimeout: 30000
  # Maximum time permitted to fetch from storage
  storageRetrievalTimeout: 30000
  # A list of prefixes that, when a record starts with one of the prefixes the
  # records data won't be stored in the db
  # storageExclusionPrefixes:
  #   - no-storage/
  #   - temporary-data/
  # A list of prefixes that, when a record is updated via setData and it matches one of the prefixes
  # it will be permissioned and written directly to the cache and storage layers
  # storageHotPathPrefixes:
  #   - analytics/
  #   - metrics/

  # Invalid configuration: data should NOT have additional properties
listen:
  # Try finding a provider randomly rather than by the order they subscribed to.
  shuffleProviders: true
  # The amount of time to wait for a provider to acknowledge or reject a listen request
  responseTimeout: 500
  # The amount of time before trying to reattempt finding matches for subscriptions. This
  # is not a cheap operation so it's recommended to raise keep this at minutes rather then
  # second intervals if you are experiencing heavy loads
  rematchInterval: 60000
  # The amount of time a server will refuse to retry finding a subscriber after a previously
  # failed attempt. This is used to avoid servers constantly trying to find a match without a
  # cooldown period
  matchCooldown: 10000

httpServer:
  type: default
  options:
    # url path for http health-checks, GET requests to this path will return 200 if deepstream is alive
    healthCheckPath: /health-check
    # -- CORS --
    # if disabled, only requests with an 'Origin' header matching one specified under 'origins'
    # below will be permitted and the 'Access-Control-Allow-Credentials' response header will be
    # enabled
    allowAllOrigins: true
    # maximum allowed size of a POST request body, in bytes, defaults to 1 MB
    maxMessageSize: 1048576
    # a list of allowed origins
    origins:
      - 'https://example.com'
    # Options required to create an ssl app
    # ssl:
    #   key: fileLoad(ssl/key.pem)
    #   cert: fileLoad(ssl/cert.pem)
    #   ca: ...

# Connection Endpoint Configuration
# to disable, replace configuration with null eg. `http: null`
connectionEndpoints:
  - type: ws-binary
    options:
      # url path websocket connections connect to
      urlPath: /deepstream
      # the amount of milliseconds between each ping/heartbeat message
      heartbeatInterval: 30000
      # the amount of milliseconds that writes to sockets are buffered
      outgoingBufferTimeout: 0
      # the maximum amount of bytes to buffer before flushing, stops the client from large enough packages
      # to block its responsiveness
      maxBufferByteSize: 100000

      # Security
      # should the server log invalid auth data, defaults to false
      logInvalidAuthData: false
      # amount of time a connection can remain open while not being logged in
      unauthenticatedClientTimeout: 180000
      # invalid login attempts before the connection is cut
      maxAuthAttempts: 3
      # maximum allowed size of an individual message in bytes
      maxMessageSize: 1048576

  - type: http
    options:
      # allow 'authData' parameter in POST requests, if disabled only token and OPEN auth is
      # possible
      allowAuthData: true
      # path for POST requests
      postPath: /api
      # path for GET requests
      getPath: /api
      # should the server log invalid auth data, defaults to false
      logInvalidAuthData: false
      # http request timeout in milliseconds, defaults to 20000
      requestTimeout: 20000

# Logger Configuration
logger:
  # use the default logger, this does not currently support meta objects
  type: default
  options:
    colors: true

storage:
  name: mongodb
  options:
    connectionString: 'mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false'
    db: deepstream

# Authentication
auth:
  # - type: none

  # # reading users and passwords from the storage layer
  - type: storage
    options:
      # the table users are stored in storage
      table: Users
      # the split character used for tables (defaults to /)
      tableSplitChar: string
      # automatically create users if they don't exist in the database
      createUser: true
      # the name of a HMAC digest algorithm
      hash: 'md5'
      # the number of times the algorithm should be applied
      iterations: 100
      # the length of the resulting key
      keyLength: 32

# Permissioning
permission:
  type: config
  options:
    # Permissions file
    permissions: fileLoad(permissions.yml)
    # Amount of times nested cross-references will be loaded. Avoids endless loops
    maxRuleIterations: 3
    # PermissionResults are cached to increase performance. Lower number means more loading
    cacheEvacuationInterval: 60000

monitoring:
  type: none

My Code

const { Deepstream } = require('@deepstream/server')
const MongoDBStorageConnector = require( 'deepstream.io-storage-mongodb' )

const server = new Deepstream()

server.set( 'storage', new MongoDBStorageConnector({
    connectionString: 'mongodb://localhost:27017/deepstream',
    splitChar: '/'
}));

server.start()

Full Logs

CONFIG_TRANSFORM | Loaded content from /var/www/deepstream-server/conf/permissions.yml for fileLoad(permissions.yml)
INFO | State transition (start): CONFIG_LOADED -> LOGGER_INIT
INFO | logger ready: std out/err at level 1
INFO | server name: l7x0fehq-rcrg81yuegw0
INFO | deepstream version: 6.2.1
INFO | configuration file loaded from conf/config.yml
INFO | State transition (logger-started): LOGGER_INIT -> SERVICE_INIT
PLUGIN_INITIALIZATION_ERROR | storage needs to implement async whenReady and close, please look at the DeepstreamPlugin API here
CLUSTER_JOIN | l7x0fehq-rcrg81yuegw0
CLUSTER_SIZE | The cluster size is now 1
TELEMETRY | INFO | Telemetry disabled
INFO | monitoring ready: Noop Monitoring
INFO | subscriptions ready: Subscription Registry
INFO | cache ready: Local Cache
INFO | permission ready: Valve Permissions
INFO | locks ready: Distributed Lock Registry
INFO | clusterNode ready: Single Cluster Node
INFO | clusterRegistry ready: Distributed Cluster Registry
INFO | clusterStates ready: Distributed State Registry
INFO | telemetry ready: Deepstream Telemetry
(node:17826) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
INFO | Listening for http connections on 0.0.0.0:6020
INFO | Listening for health checks on path /health-check
INFO | httpService ready: NodeJS HTTP Service

/var/www/deepstream-server/node_modules/@deepstream/server/src/services/authentication/storage/storage-based-authentication.ts:50
    await this.services.storage.whenReady()
                                ^
TypeError: this.services.storage.whenReady is not a function
    at StorageBasedAuthentication.whenReady (/var/www/deepstream-server/node_modules/@deepstream/server/src/services/authentication/storage/storage-based-authentication.ts:50:33)
    at /var/www/deepstream-server/node_modules/@deepstream/server/src/services/authentication/combine/combine-authentication.ts:22:53
    at Array.map (<anonymous>)
    at CombineAuthentication.whenReady (/var/www/deepstream-server/node_modules/@deepstream/server/src/services/authentication/combine/combine-authentication.ts:22:34)
    at new DependencyInitialiser (/var/www/deepstream-server/node_modules/@deepstream/server/src/utils/dependency-initialiser.ts:30:8)
    at /var/www/deepstream-server/node_modules/@deepstream/server/src/deepstream.io.ts:255:27
    at Array.reduce (<anonymous>)
    at Deepstream.serviceInit (/var/www/deepstream-server/node_modules/@deepstream/server/src/deepstream.io.ts:250:54)
    at Deepstream.transition (/var/www/deepstream-server/node_modules/@deepstream/server/src/deepstream.io.ts:191:28)
    at Deepstream.loggerInit (/var/www/deepstream-server/node_modules/@deepstream/server/src/deepstream.io.ts:243:10)