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

logging: panic in resource dection for Cloud Functions #3990

Closed
someone1 opened this issue Apr 22, 2021 · 6 comments · Fixed by #3997
Closed

logging: panic in resource dection for Cloud Functions #3990

someone1 opened this issue Apr 22, 2021 · 6 comments · Fixed by #3997
Assignees
Labels
api: logging Issues related to the Cloud Logging API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@someone1
Copy link
Contributor

Client

Logging

Environment

Go 1.13 on Cloud Functions

Updating only the dependency in our project resulted in this panic for our Cloud Function

panic: runtime error: slice bounds out of range [:-1]

goroutine 1 [running]:
functions/vendor/cloud.google.com/go/logging.regionFromZone(...)
	/workspace/src/functions/vendor/cloud.google.com/go/logging/logging.go:407
functions/vendor/cloud.google.com/go/logging.detectCloudFunction(0x1379001)
	/workspace/src/functions/vendor/cloud.google.com/go/logging/logging.go:360 +0x2db
functions/vendor/cloud.google.com/go/logging.detectResource.func1()
	/workspace/src/functions/vendor/cloud.google.com/go/logging/logging.go:374 +0x6a
sync.(*Once).doSlow(0x214d888, 0x13c8d80)
	/usr/local/go/src/sync/once.go:66 +0xe3
sync.(*Once).Do(...)
	/usr/local/go/src/sync/once.go:57
functions/vendor/cloud.google.com/go/logging.detectResource(0x120)
	/workspace/src/functions/vendor/cloud.google.com/go/logging/logging.go:367 +0x59
functions/vendor/cloud.google.com/go/logging.(*Client).Logger(0xc00008ef00, 0x1379ef4, 0x7, 0xc000933cb8, 0x2, 0x2, 0xc00027c000)
	/workspace/src/functions/vendor/cloud.google.com/go/logging/logging.go:523 +0x34

Related to #3909

@someone1 someone1 added the triage me I really want to be triaged. label Apr 22, 2021
@product-auto-label product-auto-label bot added the api: logging Issues related to the Cloud Logging API. label Apr 22, 2021
@someone1
Copy link
Contributor Author

cc @nicoleczhu

@codyoss codyoss added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Apr 22, 2021
@0xSage 0xSage added the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Apr 22, 2021
@0xSage
Copy link
Contributor

0xSage commented Apr 23, 2021

PR to fix this is in, thanks for reporting @someone1 !

Out of curiosity, was your zone a nil value or just didn't contain -'s? I'm curious under what circumstances the zone returned could be a different format than -

@someone1
Copy link
Contributor Author

someone1 commented Apr 23, 2021

Code:

package testenv

import (
	"net/http"
	"net/http/httputil"
	"os"
	"strings"

	"cloud.google.com/go/compute/metadata"
)

func DumpEnv(w http.ResponseWriter, r *http.Request) {
	_, _ = w.Write([]byte(strings.Join(os.Environ(), "\n")))

	b, _ := httputil.DumpRequest(r, false)
	_, _ = w.Write(b)

	zone, _ := metadata.Zone()
	_, _ = w.Write([]byte("zone=" + zone))
}

Command:

$ go version
go version go1.14.15 linux/amd64
$ go mod init example.com/testenv
$ go mod edit -go=1.13
$ go get cloud.google.com/go/compute/metadata
$ go mod tidy
$ go mod vendor
$ gcloud functions deploy DumpEnv --runtime go113 --trigger-http --project=$PROJECT_ID --allow-unauthenticated

Response:

PATH=/layers/google.go.build/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
K_SERVICE=DumpEnv
DEBIAN_FRONTEND=noninteractive
GCF_BLOCK_RUNTIME_go112=410
S2A_ACCESS_TOKEN=<REMOVED>
PORT=8080
K_REVISION=7
GOROOT=/usr/local/go/
HOME=/root
CGO_ENABLED=1
FUNCTION_SIGNATURE_TYPE=http
GAE_RUNTIME=go113
FUNCTION_TARGET=DumpEnv
PWD=/workspace
GCF_BLOCK_RUNTIME_nodejs6=410

GET / HTTP/1.1
Host: us-central1-$PROJECT_ID.cloudfunctions.net
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: close
Forwarded: for="<REMOVED>";proto=https
Function-Execution-Id: mwn7qym1cgwj
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
Sec-Ch-Ua-Mobile: ?0
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Sec-Fetch-User: ?1
Traceparent: 00-c8634ec7c009f52002c327dc316067c4-5c08e8e6651c53ff-01
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36
X-Appengine-City: <REMOVED>
X-Appengine-Citylatlong: <REMOVED>
X-Appengine-Country: US
X-Appengine-Default-Version-Hostname: <REMOVED>
X-Appengine-Https: on
X-Appengine-Region: <REMOVED>
X-Appengine-Request-Log-Id: 60832c7d00ff0e935ebf6315950001737e79386334303232633538343635353835382d7470000135383463643435656330336537626462663130316466386532386233323835353a37000100
X-Appengine-Timeout-Ms: 599999
X-Appengine-User-Ip: <REMOVED>
X-Cloud-Trace-Context: c8634ec7c009f52002c327dc316067c4/6631806527539532799;o=1
X-Forwarded-For: <REMOVED>
X-Forwarded-Proto: https

zone=us6

@someone1
Copy link
Contributor Author

@nicoleczhu - did that provide the answer you were looking for? It seems that the assumption Cloud Functions would return a location/zone in the format documented is not the case in this environment (e.g. us6 vs us-central1)

@dylanmpeck
Copy link

Experiencing this same issue in a Qwiklab. Calling logger := client.Logger(logName).StandardLogger(logging.Info) in a Cloud Function with Go 1.13 is giving the exact same panic error that someone1 reported.

Downgrading the logging module to v1.3.0 removed the error.

@nicoleczhu - will that PR be merged/in effect relatively soon?

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 30, 2021
@0xSage
Copy link
Contributor

0xSage commented May 3, 2021

Hi @dylanmpeck @someone1 , thanks for the context. I'm back from a 1 week vacation. Plan to get this in asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants