Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/apiserver/profiling/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/pingcap/tidb-dashboard/pkg/apiserver/model"
"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/dbstore"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
"github.com/pingcap/tidb-dashboard/pkg/pd"
)

Expand Down Expand Up @@ -50,7 +49,6 @@ type ServiceParams struct {
ConfigManager *config.DynamicConfigManager
LocalStore *dbstore.DB

HTTPClient *httpc.Client
EtcdClient *clientv3.Client
PDClient *pd.Client
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/apiserver/statement/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package statement

import (
"context"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -90,8 +91,9 @@ func (s *Service) queryStatements(
)
}
}

err = query.Find(&result).Error
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
err = query.WithContext(ctx).Find(&result).Error
return
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/httpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func (c *Client) SendRequest(
if err != nil {
return nil, err
}
return res.Body()
defer res.Response.Body.Close()
return io.ReadAll(res.Response.Body)
}

func (c *Client) Send(
Expand Down
5 changes: 5 additions & 0 deletions pkg/tidb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func (c *Client) OpenSQLConn(user string, pass string) (*gorm.DB, error) {

if err := db.Exec(fmt.Sprintf("SET SESSION max_execution_time = '%d'", defaultTiDBSQLExecutionTimeoutMs)).Error; err != nil {
log.Error("Failed to set max_execution_time", zap.Error(err))
if d, err := db.DB(); err == nil && db != nil {
if cerr := d.Close(); cerr != nil {
log.Error("Failed to close database after setting max_execution_time", zap.Error(cerr))
}
}
return nil, ErrTiDBClientRequestFailed.Wrap(err, "failed to set max_execution_time")
}

Expand Down
18 changes: 16 additions & 2 deletions pkg/tidb/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,29 @@ func (p *proxy) serve(in net.Conn) {
_ = in.Close()
return
}
deadline := time.Now().Add(10 * time.Minute)
if err := in.SetDeadline(deadline); err != nil {
log.Warn("input set deadline failed", zap.Error(err))
_ = in.Close()
return
}
if err := out.SetReadDeadline(deadline); err != nil {
log.Warn("output set deadline failed", zap.Error(err))
_ = in.Close()
return
}
done := make(chan struct{})
// bidirectional copy
go func() {
defer func() {
done <- struct{}{}
}()
// nolint
io.Copy(in, out)
_ = in.Close()
_ = out.Close()
}()
// nolint
io.Copy(out, in)
<-done
_ = out.Close()
_ = in.Close()
}
Expand Down