Skip to content

While streaming data, pausing the stream results in "TypeError: request.pause is not a function" #799

Closed

Description

@omniva

I want to stream 1 million+ rows from mssql database to another database. To deal with the Backpressure (mssql database is way faster) I want to pause the stream until the data at hand is processed (and prevent Memory exhaustion).

However when using the example from this repository I keep running into this error:
"TypeError: request.pause is not a function"

Code snippet

const sql = require('mssql');

const config = {
  user: 'user-name',
  password: 'password',
  server: 'hostname,
  database: 'databasename',
  options: {
      encrypt: true // Use this if you're on Windows Azure
  }
}

sql.connect(config, err => {
  if (err) {
    // @todo log error
  }
  else{
    var rowsToProcess = [];
    var request = new sql.Request();
    request.stream = true;
    request.query('select * from table_name')

    request.on('row', row => {
      rowsToProcess.push(row);
      if (rowsToProcess.length > 100) {
        request.pause();
        processRows();
      }
    });

    request.on('done', () => {
      processRows();
      sql.close();
    })

    function processRows() {
      rowsToProcess = [];
      request.resume();
    }
  }
});

Running code snippet results in following error:

TypeError: request.pause is not a function
    at Request.request.on.row (/Users/folder/test.js:26:17)
    at Request.emit (events.js:182:13)
    at Request.req.on.columns (/Users/folder/node_modules/mssql/lib/tedious.js:780:20)
    at Request.emit (events.js:182:13)
    at Parser.<anonymous> (/Users/folder/node_modules/mssql/node_modules/tedious/lib/connection.js:744:28)
    at Parser.emit (events.js:182:13)
    at Parser.<anonymous> (/Users/folder/node_modules/mssql/node_modules/tedious/lib/token/token-stream-parser.js:54:15)
    at Parser.emit (events.js:182:13)
    at addChunk (/Users/folder/node_modules/readable-stream/lib/_stream_readable.js:291:12)
    at readableAddChunk (/Users/folder/node_modules/readable-stream/lib/_stream_readable.js:278:11)

Software versions

  • NodeJS: v10.15.0
  • node-mssql: mssql": "^4.3.1"
  • SQL Server: (azure)

Does anyone have a clue?

Activity

  1. changed the title [-]While streaming data, pausing the streams results in "TypeError: request.pause is not a function"[/-] [+]While streaming data, pausing the stream results in "TypeError: request.pause is not a function"[/+] on Feb 10, 2019
  2. dhensby commented on Feb 11, 2019

    @dhensby
    Collaborator

    You need to use v5

  3. charutiwari04 commented on Feb 28, 2019

    @charutiwari04

    Hi, I am facing the similar issue.
    Software versions:

    "mssql": "^4.1.0",(Latest is 4.3.2)
    "connect-mssql": "^1.5.0",
    nodeJS : v8.12.0
    Can someone help? We need to use v5 of what?

  4. dhensby commented on Feb 28, 2019

    @dhensby
    Collaborator

    Of this library

  5. charutiwari04 commented on Feb 28, 2019

    @charutiwari04

    After installing v5.0.0-beta.1 version. It is not connecting to database. Following error is coming:

    error: Error connecting database! {"timestamp":"2019-02-28T11:31:14-08:00"}
    TypeError: The "config.options.textsize" property must be of type number or null.
    at new Connection (/Users//node_modules/tedious/lib/connection.js:589:17)
    at base.Promise (/Users//node_modules/mssql/lib/tedious.js:237:23)
    at new Promise ()
    at ConnectionPool._poolCreate (/Users//node_modules/mssql/lib/tedious.js:195:12)
    at ConnectionPool._connect (/Users//node_modules/mssql/lib/base.js:244:10)
    at ConnectionPool.connect (/Users//node_modules/mssql/lib/base.js:214:12)

  6. charutiwari04 commented on Feb 28, 2019

    @charutiwari04

    Looks like somewhere in your code config.options.textsize is set as string or something else, which should be either integer or null.

  7. dhensby commented on Mar 1, 2019

    @dhensby
    Collaborator

    @charutiwari04 what version of SQL server are you using and what is connect-mssql?

  8. dhensby commented on Mar 1, 2019

    @dhensby
    Collaborator

    as a temp fix I assume you can pass through your own textsize property in your connection config

    Also, that is from the tedious lib so you'll have to raise it there


    https://github.com/tediousjs/tedious/blob/v6.0.0/src/connection.js#L42 - this is where it's set

  9. charutiwari04 commented on Mar 1, 2019

    @charutiwari04

    Thank you @dhensby As suggested, temporarily it has been fixed. Opened tedious issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions