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.

Losing data with streaming pause / resume

See original GitHub issue

Hi, I followed the example on Github on how to use pause / resume. First of all I have to add :any to const request otherwise I get the error “The property ‘pause’ (resume) does not exist on type ‘Request’.” Instead of just emptying the rowsToProcess array I add the content to a new rowsToShow array. But in the end there are entries missing. There should be about 215.000 entries which are all shown if I don’t stream them but depending on the length (15 -100 entries) I use as a cut off there are only 207.000 to 210.000 entries. It looks that the pause/resume function does not work properly or maybe doesn’t work at all and while the processRows() is executed the data continues to be streamed and gets lost. Or did I miss something?

Also the memory usage when using stream and pause/resume is just about the same as when using the normal version.

import mssql = require(‘mssql’) import {pool} from ‘./pool’

const request:any = new mssql.Request(pool) request.stream = true let rowsToProcess:any = [] let rowsToShow:any = [] request.query(SELECT * FROM DummyTable)

request.on('row', (row:any) => {
    if (rowsToProcess.length < 15) {
        rowsToProcess.push(row)
    }
    else {
        request.pause()
        processRows()
    }
})

request.on('done', () => {
    rowsToShow.push(...rowsToProcess) //adds the last rowsToProcess to rowsToShow
    console.log(rowsToShow.length) // number of entries in rowsToShow
    res.json(rowsToShow.slice(0,100)) // shows the first 100 entries
})

function processRows() {
    rowsToShow.push(...rowsToProcess) 
    rowsToProcess = []
    request.resume()
}
  • NodeJS: 10.15.0
  • node-mssql: 5.0.0.alpha4
  • SQL Server: 2017

Can anybody help me out here? Thanks

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dhensbycommented, Feb 4, 2019

RE the :any casting issue, that’s most likely a typescript issue and so for the https://github.com/DefinitelyTyped/DefinitelyTyped repo not this library.

So marking this as fixed

0reactions
dhensbycommented, Feb 4, 2019

@gsamal v5.0.0-beta.1 tagged 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

When you pause a streaming Netflix video, is data continually ...
A portion of video may continue to download in the background, and be cached/stored locally for when the buffer runs out. This background...
Read more >
RTP Stream Pause and Resume RFC 7728 - IETF Datatracker
When PAUSE or RESUME reaches the RTP stream sender and is effective, i.e., an active RTP stream sender pauses or a resuming RTP...
Read more >
Lower your costs with the new pause and resume actions on ...
Pausing a cluster suspends compute and retains the underlying data structures and data so you can resume the cluster at a later point...
Read more >
How does pause and resume a video in progress work?
This means playback progress could be determined server-side and saved regardless of whether the user paused, closed or lost connection. To ...
Read more >
Pausing and Resuming Downloads - Apple Developer
Store the Resume Data Object When a Download Fails. You can also resume a download that has failed due to a temporary loss...
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