Skip to content

Replace Viper #1263

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

Merged
merged 23 commits into from
Mar 9, 2021
Merged

Replace Viper #1263

merged 23 commits into from
Mar 9, 2021

Conversation

MDrakos
Copy link
Member

@MDrakos MDrakos commented Feb 19, 2021

@MDrakos MDrakos requested a review from Naatan February 20, 2021 00:23
Comment on lines 159 to 160
i.rwLock.RLock()
defer i.rwLock.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

We can drop this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we still need this, otherwise we could encounter a panic attempting to read from a map that is currently being written to

Copy link
Member

Choose a reason for hiding this comment

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

How? The only way that that could happen is if a subroutine is writing to i.data, in which case it would be more appropriate to use a mutex. But I think that mutex probably makes more sense when writing than when reading.

Copy link
Member Author

Choose a reason for hiding this comment

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

The scenario you describe is also the one I'm thinking of. It is unlikely to happen in the same instance of the state tool but still possible I think. The rwLock is a mutex which is used in both Set and Get

Copy link
Contributor

Choose a reason for hiding this comment

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

A small aside: In almost all cases a RWLock costs more than the optimization it provides. In other words, it requires quite a bit of contention before it's worth using.

@MDrakos MDrakos requested a review from Naatan February 25, 2021 22:12
Comment on lines 159 to 160
i.rwLock.RLock()
defer i.rwLock.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

How? The only way that that could happen is if a subroutine is writing to i.data, in which case it would be more appropriate to use a mutex. But I think that mutex probably makes more sense when writing than when reading.

@MDrakos MDrakos requested review from Naatan and daved February 26, 2021 19:25
Comment on lines 159 to 160
i.rwLock.RLock()
defer i.rwLock.RUnlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

A small aside: In almost all cases a RWLock costs more than the optimization it provides. In other words, it requires quite a bit of contention before it's worth using.

@@ -231,6 +231,10 @@ func (i *Instance) ReadInConfig() error {

err = pl.WaitForLock(5 * time.Second)
if err != nil {
lockedErr := &lockfile.AlreadyLockedError{}
if errs.Matches(err, &lockedErr) {
return errs.Wrap(err, "Could not write config as another process appears to be using it")
Copy link
Member

Choose a reason for hiding this comment

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

Why did you just detect the error type just to wrap it with a regular error? Did you intend to localize this?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, importing locale in this package causes an import cycle. The intent here was to add some more context to the error. Do these wrapped messages not bubble up to the user in the same way as the localized errors? If so, I can remove this if it won't be helpful.

Copy link
Contributor

@daved daved Mar 3, 2021

Choose a reason for hiding this comment

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

At a glance, I think it makes sense to not return localized errors from this package, and then have handlers provide localized errors.

If that's not acceptable, I suggest that locale is doing too much by affecting persistent application state.

*Edit to add: Sorry to butt in, I was pinged by email and forgot I was only to look over the channel stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Non localized errors do not bubble up to the user. And the error chain is its own context. I think we can drop this.

@MDrakos MDrakos requested review from daved and Naatan March 3, 2021 21:07
daved
daved previously approved these changes Mar 3, 2021
Comment on lines 108 to 113
select {
case <-timer.C:
return err
default:
time.Sleep(100 * time.Millisecond)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should work fine - just noting that you had thumbed-up my suggestion to use time.Time.After instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I missed this... Using a timer requires more detailed usage: golang/go#27169 (comment)

I do think avoiding the channel by using time.Time.After is worthwhile here.

Copy link
Member Author

@MDrakos MDrakos Mar 3, 2021

Choose a reason for hiding this comment

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

Whoops, forgot to push the commit where I use time.Now().After() 🤦

Naatan
Naatan previously approved these changes Mar 8, 2021
@@ -231,6 +231,10 @@ func (i *Instance) ReadInConfig() error {

err = pl.WaitForLock(5 * time.Second)
if err != nil {
lockedErr := &lockfile.AlreadyLockedError{}
if errs.Matches(err, &lockedErr) {
return errs.Wrap(err, "Could not write config as another process appears to be using it")
Copy link
Member

Choose a reason for hiding this comment

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

Non localized errors do not bubble up to the user. And the error chain is its own context. I think we can drop this.

@MDrakos MDrakos merged commit 3282e1c into master Mar 9, 2021
@MDrakos MDrakos deleted the config-176754995 branch March 9, 2021 19:34
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.

3 participants