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

The Go SDK v1.31+ break for some reason #36380

Open
ardikabs opened this issue Sep 30, 2024 · 6 comments
Open

The Go SDK v1.31+ break for some reason #36380

ardikabs opened this issue Sep 30, 2024 · 6 comments

Comments

@ardikabs
Copy link

ardikabs commented Sep 30, 2024

Title: The Go SDK v1.31+ breaks development by requiring the Envoy process to run

Description:
It appears that because of the newly added code in the Go SDK v1.31+ as shown in

interval := time.Second
envInterval := os.Getenv("ENVOY_GOLANG_LOG_LEVEL_SYNC_INTERVAL")
if envInterval != "" {
dur, err := time.ParseDuration(envInterval)
if err == nil && dur >= time.Millisecond {
// protect against too frequent sync
interval = dur
} else {
api.LogErrorf("invalid env var ENVOY_GOLANG_LOG_LEVEL_SYNC_INTERVAL: %s", envInterval)
}
}
currLogLevel.Store(int32(C.envoyGoFilterLogLevel()))
ticker := time.NewTicker(interval)
go func() {
for {
select {
case <-ticker.C:
currLogLevel.Store(int32(C.envoyGoFilterLogLevel()))
}
}
}()
.

Repro steps:
Including the package github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http in a filter that requires unit testing will immediately cause it to break and display the following error:

SIGSEGV: segmentation violation
PC=0x0 m=0 sigcode=1 addr=0x0
signal arrived during cgo execution

goroutine 1 gp=0xc0000061c0 m=0 mp=0xca0260 [syscall, locked to thread]:
runtime.cgocall(0x7fead0, 0xc0000cbdb8)
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.linux-amd64/src/runtime/cgocall.go:167 +0x4b fp=0xc0000cbd90 sp=0xc0000cbd58 pc=0x46c74b
github.com/envoyproxy/envoy/contrib/golang/common/go/api_impl._Cfunc_envoyGoFilterLogLevel()
	_cgo_gotypes.go:67 +0x47 fp=0xc0000cbdb8 sp=0xc0000cbd90 pc=0x7ee267
github.com/envoyproxy/envoy/contrib/golang/common/go/api_impl.init.0()
	/home/runner/go/pkg/mod/github.com/envoyproxy/envoy@v1.31.2/contrib/golang/common/go/api_impl/capi_impl.go:76 +0xdb fp=0xc0000cbe20 sp=0xc0000cbdb8 pc=0x7ee43b
runtime.doInit1(0xc60710)
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.linux-amd64/src/runtime/proc.go:7278 +0xe8 fp=0xc0000cbf50 sp=0xc0000cbe20 pc=0x44b648
runtime.doInit(...)
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.linux-amd64/src/runtime/proc.go:7245
runtime.main()
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.linux-amd64/src/runtime/proc.go:254 +0x345 fp=0xc0000cbfe0 sp=0xc0000cbf50 pc=0x43d105
runtime.goexit({})
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.linux-amd64/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc0000cbfe8 sp=0xc0000cbfe0 pc=0x47adc1

It appears that the code required the envoy process to run, specifically on the following code L76:

currLogLevel.Store(int32(C.envoyGoFilterLogLevel()))
ticker := time.NewTicker(interval)

Note: The Envoy_collect tool
gathers a tarball with debug logs, config and the following admin
endpoints: /stats, /clusters and /server_info. Please note if there are
privacy concerns, sanitize the data prior to sharing the tarball/pasting.

Admin and Stats Output:

Include the admin output for the following endpoints: /stats,
/clusters, /routes, /server_info. For more information, refer to the
admin endpoint documentation.

Note: If there are privacy concerns, sanitize the data prior to
sharing.

Config:

Include the config used to configure Envoy.

Logs:

Include the access logs and the Envoy logs.

Note: If there are privacy concerns, sanitize the data prior to
sharing.

[optional Relevant Links:]
Slack thread: https://envoyproxy.slack.com/archives/C04QNSXC7U0/p1727604052263089

@ardikabs ardikabs added bug triage Issue requires triage labels Sep 30, 2024
@ardikabs
Copy link
Author

cc @doujiang24

@doujiang24
Copy link
Member

cc @spacewander

@spacewander
Copy link
Contributor

Including the package github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http in a filter that requires unit testing will immediately cause it to break and display the following error

The break is because the unit test executes C.xx functions exported by Envoy outside the Envoy process. It's recommended to move the github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http outside the uniting test path if the test doesn't run on an Envoy. Because the golang/filters/http/source/go/pkg/http provides some functions that will be executed in Envoy, it is unavoidable to run into the C.xx.

In fact, import golang/filters/http/source/go/pkg/http will break the compile in some Mac environments even before 1.31. For example, in my dev machine I will get:

dyld[72971]: symbol not found in flat namespace (_envoyGoConfigHttpFinalize)
signal: abort trap

It's lucky if you don't mean any problem caused by this before Envoy 1.31.

There are some ways to solve this problem. For example, in HTNN we move the golang/filters/http/source/go/pkg/http in a separate package https://github.com/mosn/htnn/blob/main/api/tests/integration/libgolang/main.go so it won't affect the unit test. You can also find some useful skills in HTNN.

As you are running unit test... Moving this part to a new package also improves the coverage as you can't really run into it in your unit test.

@ardikabs
Copy link
Author

As you are running unit test... Moving this part to a new package also improves the coverage as you can't really run into it in your unit test.

which means it is intended to be exactly like that, yes @spacewander?

ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved because the underlying package requires
Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved because the underlying package requires
Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved because the underlying package requires
Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>
ardikabs added a commit to ardikabs/gonvoy that referenced this issue Sep 30, 2024
* feat: bump envoy-sdk version

Signed-off-by: Ardika Bagus <me@ardikabs.com>

* feat: bump go version

Signed-off-by: Ardika Bagus <me@ardikabs.com>

* fix: move RunHttpFilter to dedicated package

- RunHttpFilter moved and renamed to RegisterHttpFilter
  because the underlying package requires Envoy process to run, ref: envoyproxy/envoy#36380
- Bump Envoy version on test suite

Signed-off-by: Ardika Bagus <me@ardikabs.com>

---------

Signed-off-by: Ardika Bagus <me@ardikabs.com>
@kyessenov kyessenov added area/go and removed triage Issue requires triage labels Sep 30, 2024
@kyessenov
Copy link
Contributor

CC @doujiang24

@spacewander
Copy link
Contributor

Sorry for not replying in time. We are on holiday these days.

As you are running unit test... Moving this part to a new package also improves the coverage as you can't really run into it in your unit test.

which means it is intended to be exactly like that, yes @spacewander?

Not intended, but it is recommended to do this. Putting this part on the same package doesn't have enough benefits, and moving it to a separate package can improve the modularization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants