MongoDB - InsertMany: incomplete read of message header: context deadline exceeded

Viewed 341

I have a service, which pulls logfiles from different remote servers and pushes them into a MongoDB line by line. I'm using InsertMany() for this and the single log-files are processed in different goroutines, which get the mongo.Client as parameter for concurrent use.

Everything is running fine but at some point I start getting this error in my error log: {"error":"connection(127.0.0.1:27017[-11]) incomplete read of message header: context deadline exceeded"}

The Code throwing the error looks like this:

func InsertManyLines(col *mongo.Collection, slds []interface{}) {
    connectionTimeout := time.Duration(15)
    ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout*time.Second)
    defer cancel()
    opts := options.InsertMany().SetOrdered(false)
    _, err := col.InsertMany(ctx, slds, opts)
    if err != nil {
        service.LogError(err, "InsertManyLines")
    }
}

I ran the function before with a context without timeout and got this error: {"error":"server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp [::1]:27017: connect: connection refused }, ] }"}

The services runs every 10 minutes and usually finishes after 4 minutes. With the error becoming more over time the service gets slower and ultimately hiccups with not finishing before 10 minutes. The Mongo.Client is connected at the startup of the service and the use throughout it's lifetime. The Client never throws an error while connecting.

I dont't really know what to take from the incomplete read of message header part. How can I prevent this from happening? Or has someone already experienced the error?

0 Answers
Related