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

off-by-one error causes Node to hang after progress is complete (0.1.0 regression) #19

Closed
glasser opened this issue Nov 19, 2012 · 5 comments

Comments

@glasser
Copy link

glasser commented Nov 19, 2012

This is a regression in 0.1.0 from 0.0.5.

Since progress now uses readline, it resumes stdin when you start your bar and tries to pause it again (via this.rl.close()) when the bar is complete. However, due to an off-by-one error, it doesn't actually call this.rl.close until 1 tick past total. So if you are using progress in a simple command-line tool which otherwise doesn't use stdin, using progress 0.1.0 means that stdin will be left resumed and your program will hang. For example, the following program:

var ProgressBar = require('progress');
var bar = new ProgressBar(':bar', {total: 2});
bar.tick();

hangs with 0.1.0 but not with 0.0.5.

The simplest fix for this would be to change the // progress complete code from

  if ((this.curr += len) > this.total) {

to

  if ((this.curr += len) >= this.total) {

However, it seems unfortunate that progress has to interact with stdin at all. Maybe just don't use readline? Or instead of passing process.stdin to readline, pass a dummy object that ignores the methods that are called on it?

I'm happy to submit a pull request to do any of the above, depending on which makes most sense to you.

@tj
Copy link
Member

tj commented Nov 21, 2012

meh doesn't matter to me I dont use this anymore, I can add you as a committer if you want

@tj
Copy link
Member

tj commented Nov 21, 2012

IMO fuck windows, it just messes with all simple things

@glasser
Copy link
Author

glasser commented Nov 21, 2012

Uh, sure. Using readline was just for windows, so maybe we should just revert the readline change?
Or I'm happy to make the one-character > to >= change if you add me as a committer, or send you the pull request...

@tj tj closed this as completed in 008a2ec Nov 21, 2012
@Jabbers
Copy link

Jabbers commented Nov 21, 2012

lol I just ran into this issue.. perfect timing!

@piuccio
Copy link

piuccio commented Feb 26, 2013

Would it be possible to publish a 0.1.1 release with this fix?

tj added a commit that referenced this issue Jun 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants