Skip to content

Fix clash between progress meter and credential helper - #1886

Merged
technoweenie merged 4 commits into
masterfrom
progress-cred-clash
Jan 26, 2017
Merged

technoweenie merged 4 commits into
masterfrom
progress-cred-clash

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

This is an attempt to fix #847. It pauses the progress meter before making the batch api request, and then starts it when it passing the batch api response to the transfer adapters. This works because:

  • (progress.Meter) Start(), Finish(), and Pause() internally use channels and atomic/sync. No need for that sync.Once in tq.TransferQueue.
  • The tq.TransferQueue only transfers items from a single batch concurrently. The sequence (Batch API -> n transfer adapter workers) runs sequentially, so that the next batch (if needed) can process the retries from the previous batch.

Unfortunately, there isn't really a way to test this, since it requires interactive input. Here's an example of this PR working (with a tiny hack to change the batch size to 2):

$ git lfs fetch --all 2>&1
Scanning for all objects ever referenced...
✔ 9 objects found
Fetching objects...
Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (0 of 9 files) 0 B / 1.03 MB                                                                                                                                                                                                        Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (3 of 9 files) 356.27 KB / 1.03 MB                                                                                                                                                                                                  Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (5 of 9 files) 886.59 KB / 1.03 MB                                                                                                                                                                                                  Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (7 of 9 files) 948.33 KB / 1.03 MB                                                                                                                                                                                                  Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (9 of 9 files) 1000.70 KB / 1.03 MB

Here's the same, without pausing:

$ git lfs fetch --all 2>&1
Scanning for all objects ever referenced...
✔ 9 objects found
Fetching objects...
Username for 'https://github.com': technoweenie
Password for 'https://[email protected]':
Git LFS: (1 of 9 files) 0 B / 1.03 MB                                                                                                                                                                                                        UGit LFS: (2 of 9 files) 0 B / 1.03 MB

@ttaylorr ttaylorr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great -- I'm psyched that this was easier than my estimation.

I posted one nit (which you can feel free to ignore), and one clarifying question to make sure that I'm on the same page with how this works when Batch() early-returns.

Other than that, I think this is ready to merge 👍 .

Comment thread progress/meter.go Outdated
}

func (p *ProgressMeter) Pause() {
if atomic.SwapInt32(&p.started, 0) == 1 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Using atomic.CompareAndSwapInt32(&p.started, 1, 0) accomplishes the same behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good call. This was copy pasta from Start(), but I'll tweak both.

Comment thread tq/transfer_queue.go
}

q.useAdapter(bRes.TransferAdapterName)
q.startProgress.Do(q.meter.Start)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we resume the progress meter, we have two opportunities to bail out early: on L302 and L306. I think both of those are fine, since we'd exit this function early, and the progress meter would get resumed the next time a new batch was enqueued. There'd be no issues with calling Pause() twice, since there's a CompareAndSwap<T> operation guarding the channel send into p.finished.

@technoweenie would you mind double checking my thinking on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit. I went ahead and added some tests in the progress package to assert that Start() and Pause() can be called multiple times.

@ttaylorr ttaylorr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing. Looks like there are some test failures, but I'm throwing up my approval to unblock your merge.

@technoweenie

Copy link
Copy Markdown
Contributor Author

Well, since I made Start() and Pause() safe for multiple calls, I went ahead and did the same for Finish(). Also, calling Finish() means that Start() and Pause() can never be called again.

@technoweenie

Copy link
Copy Markdown
Contributor Author

Welp, those changes did not make things happier. I backed out of them in this PR.

@technoweenie
technoweenie merged commit 9bc835c into master Jan 26, 2017
@technoweenie
technoweenie deleted the progress-cred-clash branch January 26, 2017 16:52
@ttaylorr

Copy link
Copy Markdown
Contributor

Welp, those changes did not make things happier. I backed out of them in this PR.

👍

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

Successfully merging this pull request may close these issues.

credential output hidden while transferring files

2 participants