Describe the bug
When I use the official code example: Text to speech to in-memory stream, I encounter the following panic message, which appears to be a segmentation fault. My guess is that after the stream reads to io.EOF and exits the stream Read loop to start executing defer speechSynthesizer.Close(), the SynthesisCompleted event callback happens to start executing at the same time. Since these two events cannot execute concurrently, a memory segmentation fault occurs.
Since I don't know the specific implementation logic within the speech sdk shared object library, please help confirm the possible cause of this problem.
Env
# go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/app/go.mod'
GOWORK=''
CGO_CFLAGS='-I/app/lib/speechsdk_1.45.0/include/c_api'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-L/app/lib/speechsdk_1.45.0/lib/x64 -lMicrosoft.CognitiveServices.Speech.core'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2996227142=/tmp/go-build -gno-record-gcc-switches'
# speechsdk version
speechsdk_1.45.0
# go.mod
github.com/Microsoft/cognitive-services-speech-sdk-go v1.43.1-0.20250418171739-32d0edd08e1f
Synthesis started.
Synthesizing, audio chunk size 9766.
Synthesizing, audio chunk size 10928.
Synthesizing, audio chunk size 2306.
Read [23000] bytes from audio data stream, Speech synthesized to speaker for text [Hello.].
Synthesized, audio length 23000.
SIGSEGV: segmentation violation
PC=0x0 m=22 sigcode=1 addr=0x0
signal arrived during cgo execution
goroutine 8946339 gp=0xc03ff4e1c0 m=22 mp=0xc026176e08 [syscall]:
runtime.cgocall(0x188e9fa, 0xc02558d9a8)
/usr/local/go/src/runtime/cgocall.go:167 +0x4b fp=0xc02558d980 sp=0xc02558d948 pc=0x47bdab
github.com/Microsoft/cognitive-services-speech-sdk-go/speech._Cfunc_synthesizer_handle_release(0x7f7b2c88b638)
_cgo_gotypes.go:1910 +0x48 fp=0xc02558d9a8 sp=0xc02558d980 pc=0x12e5368
github.com/Microsoft/cognitive-services-speech-sdk-go/speech.(*SpeechSynthesizer).Close(0xc04427f680)
/root/go/pkg/mod/github.com/!microsoft/cognitive-services-speech-sdk-go@v1.43.1-0.20250418171739-32d0edd08e1f/speech/speech_synthesizer.go:317 +0xef fp=0xc02558d9d0 sp=0xc02558d9a8 pc=0x12f330f
Describe the bug
When I use the official code example: Text to speech to in-memory stream, I encounter the following panic message, which appears to be a segmentation fault. My guess is that after the stream reads to io.EOF and exits the stream Read loop to start executing
defer speechSynthesizer.Close(), theSynthesisCompletedevent callback happens to start executing at the same time. Since these two events cannot execute concurrently, a memory segmentation fault occurs.Since I don't know the specific implementation logic within the speech sdk shared object library, please help confirm the possible cause of this problem.
Env