-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
support system variable wait_timeout. (#8245) #8346
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
@hhxcc Thanks! Please add a test case. |
/ok-to-test |
/run-all-tests |
@shenli I can only see a litter test case in conn_test.go, could you give some advise to write test case ? |
@lysu PTAL . I have do some refactor, add one test case , bu still do not know how to test the function readPacketWithTimeout. |
@hhxcc I will try to do it in tomorrow tks~ |
/run-all-tests tidb-test=pr/654 |
@hhxcc I just add a simple testcase in integeration repo which will setup a tidbserver and test them via network. |
@lysu thanks a lot. |
server/conn.go
Outdated
if !strings.Contains(errStack, "use of closed network connection") { | ||
if strings.Contains(errStack, "i/o timeout") { | ||
log.Infof("con:%d read packet timeout, close this connection.", cc.connectionID) | ||
} else if !strings.Contains(errStack, "use of closed network connection") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better use this way to detect timeout error
start := time.Now()
data, err := cc.readPacketWithTimeout()
idleTime := time.Now().Sub(start)
if err != nil {
if terror.ErrorNotEqual(err, io.EOF) {
if netErr, isNetErr := errors.Cause(err).(net.Error); isNetErr && netErr.Timeout() {
log.Infof("con:%d read packet timeout, close this connection, idle: %v, timeout: %v", cc.connectionID, idleTime, cc.getSessionVarsWaitTimeout())
} else {
errStack := errors.ErrorStack(err)
if !strings.Contains(errStack, "use of closed network connection") {
log.Errorf("con:%d read packet error, close this connection %s",
cc.connectionID, errStack)
}
}
}
return
}
detect close maybe be improve in furture too - - golang/go#4373
@hhxcc here, maybe we also take care about a not easy question: now, deadline is set on so for a corner case: someone make a big data input to tidb-server, then mysql protocol will transfer them in multiple packet, first packet arrive time is but I think wait_timeout should be "the timeout that no data on the wire", we should close connection only when it's idle, no matter how, read deadline should be set for per unbuffed at last, we should take care situation that one conn read with deadline and later read without deadline, once deadline be set, later read need be reset new deadline or 0(no timeout) or it will got unexpect timeout error. |
@lysu thank you for the explanation with so much details, I will add |
@hhxcc I think set on each @tiancaiamao @jackysp how do you think about this? |
@lysu PTAL |
/run-all-tests tidb-test=pr/654 |
LGTM & @jackysp PTAL thx |
sessionctx/variable/sysvar.go
Outdated
@@ -535,7 +535,7 @@ var defaultSysVars = []*SysVar{ | |||
{ScopeGlobal, "innodb_buffer_pool_size", "134217728"}, | |||
{ScopeGlobal, "innodb_adaptive_flushing", "ON"}, | |||
{ScopeNone, "datadir", "/usr/local/mysql/data/"}, | |||
{ScopeGlobal | ScopeSession, "wait_timeout", "28800"}, | |||
{ScopeGlobal | ScopeSession, WaitTimeout, "28800"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to define a const for 28800.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
/run-sqllogic-test |
sessionctx/variable/sysvar.go
Outdated
// WaitTimeout is the name for 'wait_timeout' system variable. | ||
WaitTimeout = "wait_timeout" | ||
// WaitTimeoutDefaultValue is the default value of 'wait_timeout' system variable. | ||
WaitTimeoutDefaultValue = "28800" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your quick fix, @hhxcc ! But we usually define the default values of system variable at
tidb/sessionctx/variable/tidb_vars.go
Line 221 in e69aa27
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok , it has been moved to tidb_vars.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
close client connection when the server waited for a long time , support system variable
wait_timeout
to define the wait time. #8245What is changed and how it works?
use TCPConn.SetReadDeadline() before readPacket()
Check List
Tests
Code changes
Related changes
This change is