Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write: broken pipe #143

Open
fengpf opened this issue Apr 28, 2021 · 11 comments
Open

write: broken pipe #143

fengpf opened this issue Apr 28, 2021 · 11 comments

Comments

@fengpf
Copy link

fengpf commented Apr 28, 2021

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

@beltran
Copy link
Owner

beltran commented Apr 29, 2021

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

@fengpf
Copy link
Author

fengpf commented May 7, 2021

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

}

@beltran
Copy link
Owner

beltran commented May 11, 2021

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

@fengpf
Copy link
Author

fengpf commented May 13, 2021

How can I avoid such problems

@beltran
Copy link
Owner

beltran commented May 14, 2021

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

@fengpf
Copy link
Author

fengpf commented May 18, 2021

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

@beltran
Copy link
Owner

beltran commented May 18, 2021

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?

@fengpf
Copy link
Author

fengpf commented May 18, 2021

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

@beltran
Copy link
Owner

beltran commented May 19, 2021

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.

@demoManito
Copy link

required for each query new conn,close conn at end

@shcw
Copy link

shcw commented Sep 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants