Search code examples
gogoogle-cloud-functionsslicegcloudgoogle-cloud-build

gcloud functions deploy go runtime error "undefined: unsafe.Slice; Error ID: 2f5e35a0"


While deploying to google cloud function, I am getting this error:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: # projectname/vendor/golang.org/x/sys/unix
src/projectname/vendor/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice; Error ID: 2f5e35a0

Here's my command:

gcloud functions deploy servicename --region=us-central1 --entry-point=gofunctionname --runtime=go116 --source=.

I am using vendoring to package my dependencies. It's been a while I have updated this function. And first time I noticed this error.

Any help would be much appreciated.


Solution

  • As DazWilkin suggested above, unsafe.Slice was added as part of Go 1.17 and GCP Functions support Go 1.16 as of now.

    I had to revert back the golang.org/x/sys module in the go.mod file and it worked for me.

    From

    golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
    

    To

    golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
    

    With this change, I am able to build and deploy the code to Google Cloud Functions.