question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
charutiwari04commented, Mar 1, 2019

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

0reactions
dhensbycommented, Mar 1, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Stream.pause is not a function when uploading file to ...
I get the error stream.pause is not a function which is called by the azure-storage at the start of the upload because the...
Read more >
What is Stream Module pause() in Node.js? - Educative.io
This method pauses the reading of data from a file. Any data that exists during this pause operation can be found in the...
Read more >
Stream | Node.js v19.3.0 Documentation
Writing data while the stream is not draining is particularly problematic for a Transform , because the Transform streams are paused by default...
Read more >
Is Request.pause useless? - Google Groups
I have to pause the request so I can handle the on 'data'. ... the TCP connection, all while the server is "paused"...
Read more >
Node.js Stream readable.pause() Method - GeeksforGeeks
Parameters: This method does not accept any parameters. Return Value: If this method is used then the reading of data is paused at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found