Skip to content

Cross compilation (Linux to Windows) produces hard to debug runtime bug #33

@kevinvalk

Description

@kevinvalk

(Problem) Description

The terraform provider https://github.com/kevinvalk/terraform-provider-transip is using gotransip and I just added automatic CI building. Because of the golang crossplatform support, I decided to just compile for all different platforms from Linux.

However, the time.LoadLocation method does not work well when cross compiling from Linux to Windows (this is related to #31). Hence, whenever you use the gotransip library that calls int time.LoadLocation, you will get the error: "The system cannot find the path specified.".

Steps to reproduce

  1. Setup a Golang toolchain on Linux
  2. Build from Linux using GOOS=windows GOARCH=amd64 go build
package main

import (
	"log"

	"github.com/transip/gotransip/v6"
	"github.com/transip/gotransip/v6/domain"
)

func main() {
	client, err := gotransip.NewClient(gotransip.DemoClientConfiguration)
	if err != nil {
		panic(err.Error())
	}

	name := "transipdemo.be"
	repository := domain.Repository{Client: client}

	domain, err := repository.GetByDomainName(name)
	if err != nil {
		log.Printf("failed to lookup domain %q: %s", name, err)
	}

	log.Printf("Domain: %v", domain)
}
  1. Run the produced executable on Windows

Note: cross compiling from Windows to Linux seems to work

Expected behaviour

2020/06/12 17:41:34 Domain: {[] ########## 0001-01-01 00:00:00 +0000 UTC  false false false transipdemo.be 2011-04-29 00:00:00 +0200 CEST 2021-04-29 00:00:00 +0200 CEST}

Actual behaviour

2020/06/12 17:41:08 failed to lookup domain "transipdemo.be": The system cannot find the path specified.
2020/06/12 17:41:08 Domain: {[] ########## 0001-01-01 00:00:00 +0000 UTC  false false false transipdemo.be 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}

Suggested fix

After some googling I found two issues having similar problems

The proper fix would be to transfer times from the back-end in UTC and just keep it in UTC. If the user of the library would like to present times in local time it is up to them to print it for a specific timezone. In that case time.Parse can be used instead of time.ParseInlocation (see https://golang.org/pkg/time/#Parse).

Second best fix would be transfer times from the back-end with timezone information. Then once again time.Parse can be used instead of time.ParseInlocation (see https://golang.org/pkg/time/#Parse).

If that is difficult (because all times are saved in Europe/Amsterdam in the back-end), then I guess the best thing would be to just create a fixed timezone instead of using LoadLocation

loc := time.FixedZone("CEST", 2*60*60)
t, _ := time.ParseInLocation(`"2006-01-02"`, `"2011-04-29"`, loc)
fmt.Println(t)

I created a patch that resolves this using the "worst" of the suggestions: https://gist.github.com/kevinvalk/02a4f78abe7a9705b3404f0992b55df8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions