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

time: cannot find zone in zip file /usr/local/go/lib/time/zoneinfo.zip #34188

Closed
govardhanpagidi opened this issue Sep 9, 2019 · 9 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@govardhanpagidi
Copy link

govardhanpagidi commented Sep 9, 2019

What version of Go are you using (go version)?

$ go version 1.11.4

Does this issue reproduce with the latest release?

Not sure

What operating system and processor architecture are you using (go env)?

OS: Ubuntu 16.x
No go Run time, Running as a .deb package

go env Output
$ go env

What did you do?

loc,err := time.LoadLocation(timeZone)

What did you expect to see?

*time.Location as a return value

What did you see instead?

error message : cannot find "Asia/Kolkata" in zip file /usr/local/go/lib/time/zoneinfo.zip

I've tried setting Variable as well but no luck!
$export ZONEINFO=/usr/share/zoneinfo/

@antong
Copy link
Contributor

antong commented Sep 9, 2019

Do you mean you have compiled a go program on some machine with Go 1.11.4, and then you transfer the binary to an Ubuntu 16.04 system without Go installed? And then you get the error on that system?

The compiled binary needs access to time zone data files on the destination system. You need to ensure this. Go cannot do it.

On Ubuntu, you might be missing the tzdata package that has provides /usr/share/zoneinfo contents. Try "apt-get install tzdata".

On the other hand, the error would imply that you have a /usr/local/go/lib/time/zoneinfo.zip file on that Ubuntu system. No ubuntu package should ever install anything to that location. Do you know where that file comes from?

@govardhanpagidi
Copy link
Author

govardhanpagidi commented Sep 10, 2019

Hi @antong , Thanks for the help!

Yes, I am running go binary as Debian package in Ubuntu(16.x) without go runtime.

And I could see zoneinfo file in usr/share/zoneinfo file system

I run locate zoneinfo command to find the zoneinfo in filesystem, it listdowns all zonefiles as below

e.g:
/usr/share/zoneinfo/right/US/Pacific
/usr/share/zoneinfo/right/US/Pacific-New
/usr/share/zoneinfo/right/US/Samoa

It means we have the zoneinfo in the filesystem but go library is not able to locate/find it seems.

i tried setting ZONEINFO variable, that also didn't work
$export ZONEINFO=/usr/share/zoneinfo/

@FiloSottile FiloSottile changed the title cannot find zone in zip file /usr/local/go/lib/time/zoneinfo.zip time: cannot find zone in zip file /usr/local/go/lib/time/zoneinfo.zip Sep 10, 2019
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 10, 2019
@FiloSottile FiloSottile added this to the Unplanned milestone Sep 10, 2019
@antong
Copy link
Contributor

antong commented Sep 11, 2019

I see two different issues that need to be figured out. First, why does the program not pick up the system tzdata on the Ubuntu system? Second, why can't the program find the zone data in zoneinfo.zip.

@pagidi , Can you confirm that that you have /usr/share/zoneinfo/Asia/Kolkata on your system and that it is readable by the user running your program?

$ md5sum /usr/share/zoneinfo/Asia/Kolkata
a38dc7a0d371d23d38dca5b5921b50e6  /usr/share/zoneinfo/Asia/Kolkata

I checked this on Ubuntu 16.04 LTS (is this what you mean with Ubuntu 16.x?). And with tzdata installed, it exists.

For the second issue, can you check whether zoneinfo.zip is readable by the user running your program, and that it contains Asia/Kolkata:

zipinfo /usr/local/go/lib/time/zoneinfo.zip |grep Kolkata
-rw-r--r--  3.0 unx      285 bx stor 19-Jul-02 00:44 Asia/Kolkata

Where did this file /usr/go/lib/time/zoneinfo.zip come from, as you say there is no Go installed? I verified that in the file distributed with Go, the Asia/Kolkata entry does exist.

I used the following program for testing (https://play.golang.org/p/lPgieqX_wj4). Can you verify that this is what you are doing?

package main

import (
	"fmt"
	"time"
)

func main() {
	loc, err := time.LoadLocation("Asia/Kolkata")
	fmt.Printf("%v %v\n", loc, err)
}

@govardhanpagidi
Copy link
Author

Hi @antong
It is working in my sandbox env where I have go runtime but not in Ubuntu server where no go is not available. The executable is .deb package.

Ideally program should try to read it from /usr/share/zoneinfo/, But I am not sure why it tries for /usr/local/go/lib/time/zoneinfo

When I look at /usr/share/zoneinfo/Asia/Kolkata file access, it has full access

ubuntu@dev-vir-abc:/usr/share/zoneinfo/Asia$ ls -l Kolkata
lrwxrwxrwx 1 root root 8 Jul 4 21:46 Kolkata -> Calcutta

Not sure what I am missing here...

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Sep 11, 2019

@pagidi Please show us the output of the exact command shown above, run on the Ubuntu server, run by the user that is running the Go program: md5sum /usr/share/zoneinfo/Asia/Kolkata. Thanks.

@govardhanpagidi
Copy link
Author

Hi @ianlancetaylor

Here is the output
app@dev-vir:/var/snap/amazon-ssm-agent/1455$ md5sum /usr/share/zoneinfo/Asia/Kolkata

a38dc7a0d371d23d38dca5b5921b50e6 /usr/share/zoneinfo/Asia/Kolkata

@ianlancetaylor
Copy link
Contributor

Thanks. Unfortunately I have no explanation for this. The Go code should always look for /usr/share/zoneinfo first. The error message you are seeing is a bit misleading; it was improved in the Go 1.12 release (#20969).

As nobody else has reported this problem I think it is likely to have something to do with your environment, but I don't know what that would be. The next debugging step I would suggest would be to run your program under strace -f and look for attempts to open /usr/share/zoneinfo/Asia/Kolkata. Presumably that open will fail and you will need to find out why.

@antong
Copy link
Contributor

antong commented Sep 12, 2019

The username and directory in the output hints that this may not be a standard way running a binary, but perhaps a snapcraft/snappy app. I don't know much about that architecture, but I've understood that dependencies are bundled and there are different forms of security confinement.

@govardhanpagidi
Copy link
Author

The problem is with my code
timezone path which I pass to time.LoadLocation(timeZone) is incorrect.

Value being passed as "Asia/Kolkata" instead Asia/Kolkata (extra double-quote)

I just trimmed the extra chars using
timezone := strings.Trim(timezone, """)

It worked

Thanks! @antong and @ianlancetaylor

@golang golang locked and limited conversation to collaborators Sep 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants