@@ -176,7 +176,7 @@ func (fn connErrorHandlerFn) HandleError(conn *Conn, err error, closed bool) {
176176
177177type ConnInterface interface {
178178 Close ()
179- exec (ctx context.Context , req frameBuilder , tracer Tracer ) (* framer , error )
179+ exec (ctx context.Context , req frameBuilder , tracer Tracer , requestTimeout time. Duration ) (* framer , error )
180180 awaitSchemaAgreement (ctx context.Context ) error
181181 executeQuery (ctx context.Context , qry * Query ) * Iter
182182 querySystem (ctx context.Context , query string , values ... interface {}) * Iter
@@ -451,8 +451,8 @@ type startupCoordinator struct {
451451
452452func (s * startupCoordinator ) setupConn (ctx context.Context ) error {
453453 var cancel context.CancelFunc
454- if s .conn .r . GetTimeout () > 0 {
455- ctx , cancel = context .WithTimeout (ctx , s .conn .r . GetTimeout () )
454+ if s .conn .cfg . ConnectTimeout > 0 {
455+ ctx , cancel = context .WithTimeout (ctx , s .conn .cfg . ConnectTimeout )
456456 } else {
457457 ctx , cancel = context .WithCancel (ctx )
458458 }
@@ -510,7 +510,7 @@ func (s *startupCoordinator) write(ctx context.Context, frame frameBuilder, star
510510 return nil , ctx .Err ()
511511 }
512512
513- framer , err := s .conn .execInternal (ctx , frame , nil , startupCompleted .Load ())
513+ framer , err := s .conn .execInternal (ctx , frame , nil , s . conn . cfg . ConnectTimeout , startupCompleted .Load ())
514514 if err != nil {
515515 return nil , err
516516 }
@@ -755,7 +755,7 @@ func (c *Conn) heartBeat(ctx context.Context) {
755755 case <- timer .C :
756756 }
757757
758- framer , err := c .exec (context .Background (), & writeOptionsFrame {}, nil )
758+ framer , err := c .exec (context .Background (), & writeOptionsFrame {}, nil , c . cfg . ConnectTimeout )
759759 if err != nil {
760760 failures ++
761761 continue
@@ -796,7 +796,7 @@ func (c *Conn) processFrame(ctx context.Context, r io.Reader) error {
796796
797797 // read a full header, ignore timeouts, as this is being ran in a loop
798798 // TODO: TCP level deadlines? or just query level deadlines?
799- if c .r . GetTimeout () > 0 {
799+ if c .readTimeout . Load () > 0 {
800800 c .r .SetReadDeadline (time.Time {})
801801 }
802802
@@ -1330,11 +1330,11 @@ func (c *Conn) addCall(call *callReq) error {
13301330 return nil
13311331}
13321332
1333- func (c * Conn ) exec (ctx context.Context , req frameBuilder , tracer Tracer ) (* framer , error ) {
1334- return c .execInternal (ctx , req , tracer , true )
1333+ func (c * Conn ) exec (ctx context.Context , req frameBuilder , tracer Tracer , requestTimeout time. Duration ) (* framer , error ) {
1334+ return c .execInternal (ctx , req , tracer , requestTimeout , true )
13351335}
13361336
1337- func (c * Conn ) execInternal (ctx context.Context , req frameBuilder , tracer Tracer , startupCompleted bool ) (* framer , error ) {
1337+ func (c * Conn ) execInternal (ctx context.Context , req frameBuilder , tracer Tracer , requestTimeout time. Duration , startupCompleted bool ) (* framer , error ) {
13381338 if ctxErr := ctx .Err (); ctxErr != nil {
13391339 return nil , & QueryError {err : ctxErr , potentiallyExecuted : false }
13401340 }
@@ -1431,7 +1431,7 @@ func (c *Conn) execInternal(ctx context.Context, req frameBuilder, tracer Tracer
14311431 }
14321432
14331433 var timeoutCh <- chan time.Time
1434- if timeout := c . r . GetTimeout () ; timeout > 0 {
1434+ if timeout := requestTimeout ; timeout > 0 {
14351435 if call .timer == nil {
14361436 call .timer = time .NewTimer (0 )
14371437 <- call .timer .C
@@ -1551,7 +1551,7 @@ type inflightPrepare struct {
15511551 preparedStatment * preparedStatment
15521552}
15531553
1554- func (c * Conn ) prepareStatement (ctx context.Context , stmt string , tracer Tracer , keyspace string ) (* preparedStatment , error ) {
1554+ func (c * Conn ) prepareStatement (ctx context.Context , stmt string , tracer Tracer , keyspace string , requestTimeout time. Duration ) (* preparedStatment , error ) {
15551555 stmtCacheKey := c .session .stmtsLRU .keyFor (c .host .HostID (), keyspace , stmt )
15561556 flight , ok := c .session .stmtsLRU .execIfMissing (stmtCacheKey , func (lru * lru.Cache ) * inflightPrepare {
15571557 flight := & inflightPrepare {
@@ -1575,7 +1575,7 @@ func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer,
15751575 // we won the race to do the load, if our context is canceled we shouldnt
15761576 // stop the load as other callers are waiting for it but this caller should get
15771577 // their context cancelled error.
1578- framer , err := c .exec (c .ctx , prep , tracer )
1578+ framer , err := c .exec (c .ctx , prep , tracer , requestTimeout )
15791579 if err != nil {
15801580 flight .err = err
15811581 c .session .stmtsLRU .remove (stmtCacheKey )
@@ -1692,7 +1692,7 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) (iter *Iter) {
16921692 if ! qry .skipPrepare && qry .shouldPrepare () {
16931693 // Prepare all DML queries. Other queries can not be prepared.
16941694 var err error
1695- info , err = c .prepareStatement (ctx , qry .stmt , qry .trace , usedKeyspace )
1695+ info , err = c .prepareStatement (ctx , qry .stmt , qry .trace , usedKeyspace , qry . GetRequestTimeout () )
16961696 if err != nil {
16971697 return & Iter {err : err }
16981698 }
@@ -1752,7 +1752,7 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) (iter *Iter) {
17521752 }
17531753 }
17541754
1755- framer , err := c .exec (ctx , frame , qry .trace )
1755+ framer , err := c .exec (ctx , frame , qry .trace , qry . GetRequestTimeout () )
17561756 if err != nil {
17571757 return & Iter {err : err }
17581758 }
@@ -1911,7 +1911,7 @@ func (c *Conn) UseKeyspace(keyspace string) error {
19111911 q := & writeQueryFrame {statement : `USE "` + keyspace + `"` }
19121912 q .params .consistency = c .session .cons
19131913
1914- framer , err := c .exec (c .ctx , q , nil )
1914+ framer , err := c .exec (c .ctx , q , nil , c . cfg . ConnectTimeout )
19151915 if err != nil {
19161916 return err
19171917 }
@@ -1975,7 +1975,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) (iter *Iter) {
19751975 b := & req .statements [i ]
19761976
19771977 if len (entry .Args ) > 0 || entry .binding != nil {
1978- info , err := c .prepareStatement (batch .Context (), entry .Stmt , batch .trace , usedKeyspace )
1978+ info , err := c .prepareStatement (batch .Context (), entry .Stmt , batch .trace , usedKeyspace , batch . GetRequestTimeout () )
19791979 if err != nil {
19801980 return & Iter {err : err }
19811981 }
@@ -2028,7 +2028,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) (iter *Iter) {
20282028 batch .routingInfo .mu .Unlock ()
20292029
20302030 // TODO: should batch support tracing?
2031- framer , err := c .exec (batch .Context (), req , batch .trace )
2031+ framer , err := c .exec (batch .Context (), req , batch .trace , batch . GetRequestTimeout () )
20322032 if err != nil {
20332033 return & Iter {err : err }
20342034 }
0 commit comments