Reputation: 71
When I am trying to debug this Go application using VS Code and dlv, I get the following error:
Failed to launch: could not launch process: fork/exec C:\Users\MyUser\Workspaces\goworkspace\github.com...__debug_bin.exe:%1 is not a valid Win32 application.
But when I comment out the kafka code (please refer main.go) and then try to debug, the debugger works and the breakpoint is hit.
Things that I already tried:
Running the application in other machine, which worked!
Reinstalling Go on Windows.
Moving the application to a different directory.
Reinstalling and updating VSCode and the related Golang extension/tools.
Checked the environment variables but did not find anything suspicious.
Blocked the Windows Defender, but that did not work either.
Running the 'Windows Memory Diagnostics' tool.
Reinstalling tdm-gcc (used by kafka)
Using Jetbrains Goland, but getting a similar error
could not launch process: fork/exec C:\Users\MyUser\AppData\Local\Temp\GoLand___go_build_main_go.exe: %1 is not a valid Win32 application.
could not launch process: fork/exec C:\Users\MyUser\Workspaces\goworkspace\github.com\org\app-name\cmd__debug_bin: %1 is not a valid Win32 application.
Version Details :
Please refer the code below,
main.go
func main() {
log.Println("Starting api server")
cfg, err := config.LoadConfig()
if err != nil {
log.Fatalf("LoadConfig: %v", err)
}
//Kakfa Code Begin
c, err := kafka.NewKafkaConsumer(cfg)
if err != nil {
log.Fatalf("Kafka Consumer Creation: %v", err)
}
kafka.ListenToTopics(cfg, c, []string{"topic-name"})
//Kafka Code End
}
kakfa.go
package kafka
import (
"encoding/binary"
"fmt"
"github.com/my-user/config"
"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka"
)
func NewKafkaConsumer(cfg *config.Config) (*kafka.Consumer, error) {
config := cfg.Kafka
return kafka.NewConsumer(&kafka.ConfigMap{
"bootstrap.servers": config.BootstrapServers,
"security.protocol": config.SecurityProtocol,
"sasl.mechanisms": config.SASLMechanisms,
"sasl.username": config.SASLUsername,
"sasl.password": config.SASLPassword,
"group.id": config.GroupID,
"auto.offset.reset": config.AutoOffsetReset,
})
}
func ListenToTopics(cfg *config.Config, c *kafka.Consumer, topics []string) {
c.SubscribeTopics(topics, nil)
for {
msg, err := c.ReadMessage(-1)
defer c.Close()
if err == nil {
schemaID := binary.BigEndian.Uint32(msg.Value[1:5])
schema, err := getLatestAVROSchemaById(cfg, int(schemaID))
if err != nil {
panic(fmt.Sprintf("Error getting the schema with id '%d' %s", schemaID, err))
}
native, _, _ := schema.Codec.NativeFromBinary(msg.Value[5:])
value, _ := schema.Codec.TextualFromNative(nil, native)
fmt.Printf("Here is the message %s\n", string(value))
} else {
fmt.Printf("Error consuming the message: %v (%v)\n", err, msg)
}
}
}
go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\MyUser\AppData\Local\go-build
set GOENV=C:\Users\MyUser\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\MyUser\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\MyUser\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\MyUser\AppData\Local\Temp\go-build3863829792=/tmp/go-build -gno-record-gcc-switches
Please let me know if I should post this question to some specific forum/community.
Upvotes: 4
Views: 1740