Git Product home page Git Product logo

Comments (23)

vbauerster avatar vbauerster commented on May 26, 2024

Well that's intended behaviour. It happens when total <= 0 in b := p.AddBar(total). mpb treats such case as total is unknown, and a user suppose to call b.Completed() method after work is done, see this gist for example.
Why not just return if total <= 0?
Suppose one want to download a file over http. Some http servers may report size 0, but resp.Body is not empty. Usually this happens when http server doesn't support resume. So rather than return silently, mpb fallbacks to simple spinner bar, and expects user to call b.Completed() method, after job is done.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

I've implemented a fix at issue7fix branch, which will call b.Completed() implicitly.
Can you please checkout this branch, and check if it works for you?

from mpb.

kormoc avatar kormoc commented on May 26, 2024

I can confirm that this fixes the exit freeze, however it does display things oddly

foobar                                      0b /  0b [/] -9223372036854775808 %

Thanks for the quick fix though!

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Can you show your code? How do you initialise a bar?

from mpb.

kormoc avatar kormoc commented on May 26, 2024

Certainly, the code is here:

https://github.com/kormoc/bitrot_scanner/blob/master/checksumHelpers.go#L53

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Yes negative percentage is odd looking. I've fixed that, and merged to master. You can checkout.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Looking at your code

PrependCounters("%3s / %3s", mpb.UnitBytes, 18, mpb.DwidthSync|mpb.DextraSpace)

I assume you use multiple bars. For single bar, option mpb.DwidthSync has no effect.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

As for simple spinner, the [/] part, it cycles through a set of -\|/ characters. Maybe I should let user to decide whether he/she wants this spinner for such edge case (total <= 0)? It is on by default, what do you think?

from mpb.

kormoc avatar kormoc commented on May 26, 2024

Yes, we (optionally) use multiple bars. I don't mind the spinner in this case. Thanks much for the quick fix!

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

You're welcome, thanks for reporting!

from mpb.

falzm avatar falzm commented on May 26, 2024

Hi, sorry to dig this issue out of its grave but it looks like this "problem" is still present with current versions (tested with v4.9.1). The code has much changed since this issue's fix commit, I tried to track down the code but can't seem to find it in the current code base so I wonder if it may have been forgotten during a refactoring maybe?

Our actual implementation is here: https://github.com/exoscale/cli/blob/master/cmd/sos_upload.go#L170-L194
If we pass the raw file reader to PutObjectWithContext() method it works fine with empty files, but gets stuck if we pass the bar.ProxyReader(f) reader.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Hi, you're right, Read method of proxyReader never checked EOF. Should be fixed with this commit. Can you pls check, and confirm if it's fixed?
I'll bump tag after your confirmation.

from mpb.

falzm avatar falzm commented on May 26, 2024

@vbauerster tested with this commit: no improvement.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

I've simulated empty file/reader in io example, by changing this line to total := 0 and there is no freeze.

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Are you sure your build has picked up aforementioned commit?

from mpb.

falzm avatar falzm commented on May 26, 2024

Yes:

$ git diff go.mod
diff --git a/go.mod b/go.mod
index efb439f..5a23218 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,7 @@ require (
        github.com/spf13/cobra v0.0.3
        github.com/spf13/pflag v1.0.3
        github.com/spf13/viper v1.3.1
-       github.com/vbauerster/mpb/v4 v4.8.4
-       golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5
+       github.com/vbauerster/mpb/v4 v4.9.2-0.20190806152146-08e821e86ad3
+       golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
        gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
 )

$ git diff vendor/github.com/vbauerster/mpb/v4/proxyreader.go
diff --git a/vendor/github.com/vbauerster/mpb/v4/proxyreader.go b/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
index d2692cc..1e172be 100644
--- a/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
+++ b/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
@@ -18,5 +18,9 @@ func (pr *proxyReader) Read(p []byte) (n int, err error) {
                pr.bar.IncrBy(n, time.Since(pr.iT))
                pr.iT = time.Now()
        }
+       if err == io.EOF {
+               current := pr.bar.Current()
+               pr.bar.SetTotal(current, true)
+       }
        return
 }

$ make
go clean
rm -rf exo contrib/completion manpage
go build -ldflags "-s -w -X main.version=dev -X main.commit=b7f5c7dd64d3c8c08d6994519cb2d76ffabebc39" -mod=vendor -o exo

$ ./exo version
exo dev b7f5c7dd64d3c8c08d6994519cb2d76ffabebc39 (egoscale 0.18.1)

$ touch blah
$ ./exo sos upload marc-test blah
0s 0 % [--------------------------------------------------------------] blah
# ^^^ gets stuck ^^^

from mpb.

falzm avatar falzm commented on May 26, 2024

You can perform the same test on your end by checking out our repository: https://github.com/exoscale/cli

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

It asks for config which I don't have. I wonder if Read method is called at all on empty file. You can troubleshoot by putting fmt.Fprintln(os.Stderr, "read called") here, then run like ./exo 2> debug.txt. I recommend using gohack for that.

from mpb.

falzm avatar falzm commented on May 26, 2024

Tested with your instructions: the debug.txt is empty.

from mpb.

falzm avatar falzm commented on May 26, 2024

Tested with your instructions: the debug.txt is empty.

Wait nevermind, I think the debug line has not been taken by the compiler via gohack. Let me try again.

from mpb.

falzm avatar falzm commented on May 26, 2024

This time I'm positive the modified file is actually used because I got compilation error complaining about missing fmt/os package imports.

Sadly, the debug.txt remains empty:

$ git diff vendor/github.com/vbauerster/mpb/v4/proxyreader.go
diff --git a/vendor/github.com/vbauerster/mpb/v4/proxyreader.go b/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
index d2692cc..d4b142e 100644
--- a/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
+++ b/vendor/github.com/vbauerster/mpb/v4/proxyreader.go
@@ -1,7 +1,9 @@
 package mpb

 import (
+       "fmt"
        "io"
+       "os"
        "time"
 )

@@ -13,10 +15,15 @@ type proxyReader struct {
 }

 func (pr *proxyReader) Read(p []byte) (n int, err error) {
+       fmt.Fprintln(os.Stderr, "read called")
        n, err = pr.ReadCloser.Read(p)
        if n > 0 {
                pr.bar.IncrBy(n, time.Since(pr.iT))
                pr.iT = time.Now()
        }
+       if err == io.EOF {
+               current := pr.bar.Current()
+               pr.bar.SetTotal(current, true)
+       }
        return
 }

$ make
go clean
rm -rf exo contrib/completion manpage
go build -ldflags "-s -w -X main.version=dev -X main.commit=b7f5c7dd64d3c8c08d6994519cb2d76ffabebc39" -mod=vendor -o exo


$ ./exo sos upload marc-test blah 2>debug.txt
0s 0 % [--------------------------------------------------------------] blah
^C 
$ cat debug.txt
$

from mpb.

vbauerster avatar vbauerster commented on May 26, 2024

Well it means that minioClient doesn't handle it properly, however as workaround you may consider checking empty file manually and call bar.SetTotal(0, true) afterwards. Long term fix is to report upstream to minio lib.

from mpb.

falzm avatar falzm commented on May 26, 2024

Well, indeed your workaround works – thank you for that. I'll go ahead and open an issue at Minio, you can close this one.

from mpb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.