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

plugin: add test (was encoding/asn1 error when using plugin) #18584

Closed
fsenart opened this issue Jan 9, 2017 · 15 comments
Closed

plugin: add test (was encoding/asn1 error when using plugin) #18584

fsenart opened this issue Jan 9, 2017 · 15 comments
Milestone

Comments

@fsenart
Copy link

fsenart commented Jan 9, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8beta2 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/fsenart/projects"
GORACE=""
GOROOT="/home/fsenart/tools/go"
GOTOOLDIR="/home/fsenart/tools/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build746500890=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

// main.go

package main

import (
	"plugin"
	"reflect"
)

func main() {
	p, err := plugin.Open("plugin.so")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("F")
	if err != nil {
		panic(err)
	}

	// f.(func())()
	reflect.ValueOf(f).Call(nil)
}
// plugin.go

package main

import "C"
import "net/http"

func F() {
	_, err := http.Get("https://example.com")
	if err != nil {
		panic(err)
	}
}
# Makefile

test: build
	@./main

build: clean
	@go build -buildmode=plugin -o plugin.so plugin.go
	@go build -o main main.go

clean:
	@rm -rf main *.so

What did you expect to see?

I don't expect any panic to happen.

What did you see instead?

I see a panic happen.

panic: Get https://example.com: tls: failed to parse certificate from server: asn1: structure error: tags don't match (4 vs {class:0 tag:16 length:1242 isCompound:true}) {optional:false explicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} RawContent @4

goroutine 1 [running]:
plugin/unnamed-4ad3198f73971e7223d350ce7ae956cd80d817d9.F()
	/home/fsenart/projects/src/github.com/alsanium/issue_asn1/plugin.go:9 +0x65
reflect.Value.call(0x4d3820, 0xc42000f728, 0x13, 0x4ef099, 0x4, 0x0, 0x0, 0x0, 0xc42000c2e0, 0x4d3820, ...)
	/home/fsenart/tools/go/src/reflect/value.go:434 +0x91f
reflect.Value.Call(0x4d3820, 0xc42000f728, 0x13, 0x0, 0x0, 0x0, 0xc42004df68, 0x4be551, 0x0)
	/home/fsenart/tools/go/src/reflect/value.go:302 +0xa4
main.main()
	/home/fsenart/projects/src/github.com/alsanium/issue_asn1/main.go:19 +0xed
Makefile:2: recipe for target 'test' failed

Observations

  • If I don't use the reflect package, and instead make type assertion manually, then no error happens.

    f.(func())()
    // reflect.ValueOf(f).Call(nil)
  • If I don't use the plugin package, then no error happens.

    package main
    
    import (
        "net/http"
        "reflect"
    )
    
    var f interface{} = func() {
        _, err := http.Get("https://example.com")
        if err != nil {
            panic(err)
        }
    }
    
    func main() {
        //f.(func())()
        reflect.ValueOf(f).Call(nil)
    }
@fsenart fsenart changed the title encoding/asn1 side effects when using reflect to call plugin methods. encoding/asn1 side effects when using reflect to call plugin methods. Jan 9, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Jan 9, 2017

/cc @crawshaw @ianlancetaylor

@bradfitz bradfitz added this to the Go1.8Maybe milestone Jan 9, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Jan 9, 2017

Probably too late for a Go 1.8 fix, but maybe a point release.

fsenart added a commit to lifadev/archive_aws-lambda-go that referenced this issue Jan 9, 2017
@fsenart
Copy link
Author

fsenart commented Jan 10, 2017

OK. THIS IS WEIRD.

After more investigation, it seems not even related to the reflect package.

The error happens if you import any package when using the plugin package.
For example (plugin.go as above):

// main.go

package main

import (
	"fmt" // you can import any package (fails with fmt, log, json, etc.)
	"plugin"
)

func main() {
	fmt.Print() // dummy print for the import statement

	p, err := plugin.Open("plugin.so")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("F")
	if err != nil {
		panic(err)
	}

	f.(func())()
}

PS: I don't know what should be the issue title!

@ianlancetaylor ianlancetaylor changed the title encoding/asn1 side effects when using reflect to call plugin methods. plugin: encoding/asn1 error when using plugin Jan 10, 2017
@stefanahman
Copy link

Getting the same error using https://github.com/eawsy/aws-lambda-go-shim library.
After more investigation and reading this thread, I noticed the plugin import in this file.

@fsenart
Copy link
Author

fsenart commented Jan 10, 2017

@stefanahman we effectively use go plugins in this project and the issue is related to the fact that we have other imports than plugin in the referenced file (cf. above comment).

@bradfitz at the time I've opened the issue, I agree with you that the problem was very special and happen in rare cases and Go1.8Maybe milestone was ok.
But considering my last comment, you must notice that as soon as any package is imported along with the plugin package then all SSL requests fail. Isn't it a major issue to be fixed before the release of 1.8? Can you please reconsider the milestone, taking into account the new elements?

@crawshaw
Copy link
Member

Importing package plugin into a binary switches the linker to the dynamic linking codepath. Presumably that is triggering something which causes type-handling problems.

(I won't have access to a linux machine to investigate this until tomorrow.)

@cristim
Copy link

cristim commented Jan 10, 2017

@fsenart, @bradfitz IMHO having the new plugin feature break TLS when there are any other imports makes it pretty useless for a lot of web backend use cases, so I think 1.8 shouldn't be released before this issue is fixed.

@bradfitz
Copy link
Contributor

If we stopped the release train for every bug, we'd never ship.

Plugins are a new part of Go 1.8 anyway. Expect some rough edges. For instance, we disabled them entirely on Mac at the last second, and they don't work on Windows. A few more bugs are expected. That's what point releases are for.

@cristim
Copy link

cristim commented Jan 10, 2017

@bradfitz if you mentioned all that it sounds reasonable, I was just under the impression that the plugin feature was a bit more mature than that.

@schickling
Copy link

Same issue here. Thanks for investigating @fsenart 👍

@fsenart
Copy link
Author

fsenart commented Jan 10, 2017

The issue (or at least its visible symptoms) is resolved with the release of go1.8rc1 3de6e96. /cc @crawshaw @bradfitz
PS: I let you close the issue or remain it open for deep investigations.

@bradfitz
Copy link
Contributor

@crawshaw, @ianlancetaylor do you know what might've fixed this between beta2 and rc1?

@ianlancetaylor
Copy link
Contributor

It was fixed by the fix to #18252.

But we should add a test for this in misc/cgo/testplugin.

@stefanahman
Copy link

Can confirm that my issue has been resolved with v1.8rc1 😃 🎉

@bradfitz bradfitz changed the title plugin: encoding/asn1 error when using plugin plugin: add test (was encoding/asn1 error when using plugin) Jan 23, 2017
@bradfitz bradfitz modified the milestones: Go1.9, Go1.10 Jun 7, 2017
@gopherbot
Copy link

Change https://golang.org/cl/67150 mentions this issue: misc/cgo/testplugin: add test for issue 18584

@golang golang locked and limited conversation to collaborators Sep 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants