gohive
gohive copied to clipboard
write: broken pipe
hi i exec go test to query is ok,but exec main func has error:write: broken pipe
Do you have a sample code of how this is happening?
first : hi, when i exec cursor.HasMore get the err second: code is below
func SqlHive(ctx context.Context, db *gohive.Connection, result interface{}, sql string) error { cursor := db.Cursor() defer cursor.Close() start := time.Now().Unix()
cursor.Execute(ctx, sql, false)
tf := reflect.TypeOf(result)
vf := reflect.ValueOf(result).Elem()
elem := tf.Elem().Elem().Elem()
for cursor.HasMore(ctx) {
if err := cursor.Err; err != nil {
log.Error(map[string]interface{}{
"msg": "sqlHive.HasMore",
"data": map[string]interface{}{
"err": err.Error(),
"sql": sql,
},
})
return err
}
row := cursor.RowMap(ctx)
p := reflect.New(elem)
if err := mapstructure.Decode(row, p.Interface()); err != nil {
log.Error(map[string]interface{}{
"msg": "sqlHive.Decode",
"data": map[string]interface{}{
"err": err.Error(),
"sql": sql,
"row": row,
},
})
}
vf.Set(reflect.Append(vf, p))
}
if cost := time.Now().Unix() - start; cost > 10 {
log.Info(map[string]interface{}{
"msg": "SqlHive.Cost(s)",
"data": map[string]interface{}{"cost": cost, "sql": sql},
})
}
return nil
}
HasMore
may issue a request to the server so if can fail with write: broken pipe
How can I avoid such problems
How is the error happening? Is it a panic inside the call HasMore or similar? Ideally you should be able to check cursor.Err
and check if this has happened. If not, it's probably a bug in the library
It doesn't get panic inside the call HasMore. I have checked cursor.err, at the same time throw: "Write client IP: port-> server IP :port: write: broken pipe".
So it's not clear to me where you're seeingWrite client IP: port-> server IP :port: write: broken pipe
, what do you mean by at the same time you check cursor.Err, Write client IP: port-> server IP :port: write: broken pipe
is thrown? If cursor.Err has the error why just not check it?
Yes, it should be checked, but I don't know how to check for such problems. Thanks for you.
You could so something like:
if cursor.Err.Error() == "Write client IP: port-> server IP :port: write: broken pipe" {
// Recreate the cursor and the connection
}
Similar to how the error is check in this test.
required for each query new conn,close conn at end
I have a similar problem, is it related to the heartbeat ?