gohive icon indicating copy to clipboard operation
gohive copied to clipboard

write: broken pipe

Open fengpf opened this issue 3 years ago • 11 comments

hi i exec go test to query is ok,but exec main func has error:write: broken pipe

fengpf avatar Apr 28 '21 14:04 fengpf

Do you have a sample code of how this is happening?

beltran avatar Apr 29 '21 22:04 beltran

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

}

fengpf avatar May 07 '21 13:05 fengpf

HasMore may issue a request to the server so if can fail with write: broken pipe

beltran avatar May 11 '21 12:05 beltran

How can I avoid such problems

fengpf avatar May 13 '21 14:05 fengpf

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

beltran avatar May 14 '21 12:05 beltran

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".

fengpf avatar May 18 '21 02:05 fengpf

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?

beltran avatar May 18 '21 12:05 beltran

Yes, it should be checked, but I don't know how to check for such problems. Thanks for you.

fengpf avatar May 18 '21 15:05 fengpf

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.

beltran avatar May 19 '21 14:05 beltran

required for each query new conn,close conn at end

demoManito avatar Sep 14 '21 04:09 demoManito

I have a similar problem, is it related to the heartbeat ?

shcw avatar Sep 09 '22 06:09 shcw