Skip to content

Add connection read/write timeout #50

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

Closed
ghost opened this issue Mar 29, 2013 · 11 comments
Closed

Add connection read/write timeout #50

ghost opened this issue Mar 29, 2013 · 11 comments

Comments

@ghost
Copy link

ghost commented Mar 29, 2013

Can we set mysql read/write timeout,?

MYSQL_OPT_READ_TIMEOUT ..

@ghost ghost assigned julienschmidt Mar 29, 2013
@jmacd
Copy link

jmacd commented Apr 2, 2013

I'm having trouble with long-running queries, too, although I couldn't say if MYSQL_OPT_READ_TIMEOUT will solve my problem. I have a long-running SELECT statement that does some amount of CPU-intensive processing for each record. Eventually, the log shows (w/ code from March 2):

[MySQL] 2013/04/01 04:02:06 packets.go:62: EOF
[MySQL] 2013/04/01 04:02:08 packets.go:32: EOF
and an error returned to my code with String() = "driver: bad connection"

The duration my SELECT query runs before this happens is variable, so I presume this has something to do with my high CPU load and hitting some kind of timeout with MySQL. Anyway, thanks for the great code.

@arnehormann
Copy link
Member

According to the documentation, there are four timeouts which can be changed per session. They are:

You may be interested in net_write_timeout, which is 60 seconds by default.

Do you still see the problem when you issue SET SESSION net_write_timeout = 600 after opening a connection?

This can also be set by appending &net_write_timeout=600 to the DSN.

@julienschmidt
Copy link
Member

@jmacd the EOF means, that the connection was closed, probably by the server.
Can you update to beta 5 ( go get -u github.com/go-sql-driver/mysql ) and try again with net_write_timeout set to a higher value like @arnehormann suggested?

@julienschmidt
Copy link
Member

@better0332 do you have a certain issue you try to solve with a read / write timeout or is this more a general question?
I'm not sure if the driver should support this, since setting a client side timeout (in fact it is a deadline in absolute time we need to calculate every time) is quite expensive.

@ghost
Copy link
Author

ghost commented Apr 27, 2013

Our network quality is not stable, the client remote connect center mysql server. It seems like trap to driver until
/proc/sys/net/ipv4/tcp_keepalive_time
/proc/sys/net/ipv4/tcp_keepalive_intvl
/proc/sys/net/ipv4/tcp_keepalive_probes

@arnehormann
Copy link
Member

@better0332 so you solved it by changing OS settings? Is this resolved, then?

@ghost
Copy link
Author

ghost commented Apr 27, 2013

yes, i resolved and I think the read/write timeout may affect connection pool

@arnehormann
Copy link
Member

We'll close this for now. We can reopen it if @jmacd or somebody else still has problems.

@jmacd
Copy link

jmacd commented May 1, 2013

I raised net_read_timeout and net_write_timeout and it works.
Thanks,Josh.

On Tue, Apr 30, 2013 at 1:03 AM, Arne Hormann [email protected]:

We'll close this for now. We can reopen it if @jmacdhttps://github.com/jmacdor somebody else still has problems.


Reply to this email directly or view it on GitHubhttps://github.com//issues/50#issuecomment-17214289
.

@arnehormann
Copy link
Member

And it will stay closed... Thank you for getting back to us!

@shenshouer
Copy link

@arnehormann hi ,I got this issue now. The detail like:
[MySQL] 2015/03/19 14:30:25 packets.go:59: read tcp 172.16.2.105:3306: connection reset by peer
[MySQL] 2015/03/19 14:30:25 packets.go:336: Busy buffer
2015/03/19 14:30:25 [INFO] people-count/app/models.(*Platform_db_info).getAgentConnect : (platform_db.go:150) - select agents from [北京] err: [driver: bad connection]

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

No branches or pull requests

4 participants