#EOF error with Go sdk

1 messages · Page 1 of 1 (latest)

hardy mountain
#

trying to set up a connection with DG Golang sdk, keep getting the error of

EOF

from the streaming option

func (c *Client) Stream(r io.Reader) error {
klog.V(6).Infof("live.Stream() ENTER\n")

chunk := make([]byte, ChunkSize)

for {
    select {
    case <-c.ctx.Done():
        klog.V(2).Infof("stream object Done()\n")
        klog.V(6).Infof("live.Stream() LEAVE\n")
        return nil
    default:
        bytesRead, err := r.Read(chunk)
        if err != nil {
            errStr := err.Error()
            switch {
            case strings.Contains(errStr, SuccessfulSocketErr):
                klog.V(3).Infof("Graceful websocket close\n")
                klog.V(6).Infof("live.Stream() LEAVE\n")
                return nil
            case strings.Contains(errStr, FatalReadSocketErr):
                klog.V(1).Infof("Fatal socket error: %v\n", err)
                klog.V(6).Infof("live.Stream() LEAVE\n")
                return err
            case (err == io.EOF || err == io.ErrUnexpectedEOF) && !c.retry:
                klog.V(3).Infof("stream object EOF\n")
                klog.V(6).Infof("live.Stream() LEAVE\n")
                return err
            default:
                klog.V(1).Infof("r.Read error. Err: %v\n", err)
                klog.V(6).Infof("live.Stream() LEAVE\n")
                return err
            }
        }

        if bytesRead == 0 {
            klog.V(7).Infof("Skipping. bytesRead == 0\n")
            continue
        }

        byteCount, err := c.Write(chunk[:bytesRead])
        if err != nil {
            klog.V(1).Infof("w.Write failed. Err: %v\n", err)
            klog.V(6).Infof("live.Stream() LEAVE\n")
            return err
        }
        klog.V(7).Infof("io.Writer succeeded. Bytes written: %d\n", byteCount)
    }
}

}

keen marshBOT
#

Hi @hardy mountain. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the provided knowledge sources, there isn't specific information available to address the EOF error you're encountering with the Deepgram Go SDK. However, it's important to note that the EOF error typically occurs when the end of the file or stream has been reached.

In your case, it seems like the error is being handled in your code:

case (err == io.EOF || err == io.ErrUnexpectedEOF) && !c.retry:
    klog.V(3).Infof("stream object EOF\n")
    klog.V(6).Infof("live.Stream() LEAVE\n")
    return err

This suggests that the stream you're trying to read from has ended. You might want to check the source of your stream to ensure it's being correctly provided.

Also, ensure that you're using a compatible version of Go (version ^1.19) as mentioned in the Deepgram Go SDK requirements (https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk#readme-requirements).

If the issue persists, you might want to reach out to Deepgram's support or check their discussion forums for more specific guidance.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: