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

fix: work around issue with user.Lookup not returning UnknownUserError #427

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Jun 10, 2024

Per golang/go#67912, under some circumstances (on my machine) user.Lookup isn't returning UnknownUserError when it should. So before this fix I get the following test failures:

$ go test ./internals/osutil
...
FAIL: user_test.go:44: userSuite.TestRealUser

user_test.go:71:
    c.Assert(err, check.IsNil)
... value *errors.errorString = &errors.errorString{s:"user: lookup username guy: no such file or directory"} ("user: lookup username guy: no such file or directory")
...

And:

$ go test ./internals/daemon
...
----------------------------------------------------------------------
FAIL: api_files_test.go:1128: filesSuite.TestWriteErrors

api_files_test.go:1195:
    checkFileResult(c, r.Result[4], pathUserNotFound, "generic-file-error", ".*unknown user.*")
api_files_test.go:273:
    c.Check(r.Error.Message, Matches, errorMsg)
... value string = "cannot look up user and group: user: lookup username user-not-found: no such file or directory"
... regex string = ".*unknown user.*"

api_files_test.go:1196:
    checkFileResult(c, r.Result[5], pathGroupNotFound, "generic-file-error", ".*unknown group.*")
api_files_test.go:273:
    c.Check(r.Error.Message, Matches, errorMsg)
... value string = "cannot look up user and group: user: lookup groupname group-not-found: no such file or directory"
... regex string = ".*unknown group.*"
...

Per golang/go#67912, under some circumstances
(on my machine) user.Lookup isn't returning UnknownUserError when it
should.
// Workaround for https://github.com/golang/go/issues/67912, until our
// minimum Go version has a fix for that. In short, user.Lookup sometimes
// doesn't return UnknownUserError when it should.
if err != nil && strings.Contains(err.Error(), "no such file or directory") {
Copy link

Choose a reason for hiding this comment

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

Is a “C” or an en_* locale guaranteed for pebble?

I’m assuming that go localise strerror, tbh I don’t know if it does.

Copy link
Member

Choose a reason for hiding this comment

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

@benhoyt can you please replace all the string literals here with syscall.Errno(2).Error()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dimaqq Yep, Go doesn't use the C locale environment variables (thankfully!). It's a hard-coded string, see https://github.com/golang/go/blob/beaf7f3282c2548267d3c894417cc4ecacc5d575/src/syscall/syscall_unix.go#L110 and https://github.com/golang/go/blob/beaf7f3282c2548267d3c894417cc4ecacc5d575/src/syscall/zerrors_linux_amd64.go#L1361

@hpidcock Good call. One better: syscall.ENOENT.Error(). :-)

Copy link
Member

@hpidcock hpidcock left a comment

Choose a reason for hiding this comment

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

LGTM - thanks

@benhoyt benhoyt merged commit 22cdf7a into canonical:master Jun 11, 2024
16 checks passed
@benhoyt benhoyt deleted the user-lookup-workaround branch June 11, 2024 02:16
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