@@ -22,7 +22,6 @@ import (
2222 "github.com/firebirdsql/fbx/fbproto"
2323 "github.com/firebirdsql/fbx/fbproto/auth"
2424 "github.com/firebirdsql/fbx/fbproto/wirecrypt"
25- "github.com/firebirdsql/fbx/internal/cleanupctx"
2625 "github.com/firebirdsql/fbx/internal/operationerror"
2726)
2827
@@ -1424,7 +1423,7 @@ func (fbConn *FbConn) asyncClose() {
14241423func (fbConn * FbConn ) asyncCloseAfterRead (err error ) {
14251424 var netErr net.Error
14261425 if errors .As (err , & netErr ) && netErr .Timeout () {
1427- fbConn .asyncCloseWithTimeout (cleanupTimeout ())
1426+ fbConn .asyncCloseWithTimeout (fbConn . GetCleanupTimeout ())
14281427 } else {
14291428 fbConn .asyncClose ()
14301429 }
@@ -2060,7 +2059,7 @@ func (fbConn *FbConn) ExecParamsTx(ctx context.Context, tx *FBTransaction, sql s
20602059
20612060 rr := st .Exec (ctx , paramValues )
20622061 if rr .err != nil {
2063- cleanupCtx , cancel := cleanupContext (ctx )
2062+ cleanupCtx , cancel := fbConn . GetCleanupContext (ctx )
20642063 rr .err = operationerror .Join (rr .err , st .Deallocate (cleanupCtx ))
20652064 cancel ()
20662065
@@ -2199,7 +2198,7 @@ func (fbConn *FbConn) getArrayMetadata(ctx context.Context, tx *FBTransaction, s
21992198 }
22002199
22012200 defer func () {
2202- cleanupCtx , cancel := cleanupContext (ctx )
2201+ cleanupCtx , cancel := fbConn . GetCleanupContext (ctx )
22032202 _ = st .deallocateLocked (cleanupCtx )
22042203 cancel ()
22052204 }()
@@ -2295,7 +2294,7 @@ func (fbConn *FbConn) getArrayDimensions(ctx context.Context, tx *FBTransaction,
22952294 }
22962295
22972296 defer func () {
2298- cleanupCtx , cancel := cleanupContext (ctx )
2297+ cleanupCtx , cancel := fbConn . GetCleanupContext (ctx )
22992298 _ = st .deallocateLocked (cleanupCtx )
23002299 cancel ()
23012300 }()
@@ -2868,25 +2867,13 @@ func (rr *ResultReader) SetCallerErr(err error) {
28682867 }
28692868}
28702869
2871- // SetCleanupTimeout sets the timeout for the resource cleanup context.
2872- // The default timeout is 5 seconds.
2873- // It must be called before using the driver and must not be called
2874- // concurrently with driver operations.
2875- // The transmitted timeout must be at least 150 ms.
2876- func SetCleanupTimeout (timeout time.Duration ) error {
2877- return cleanupctx .SetCleanupTimeout (timeout )
2878- }
2879-
2880- // cleanupContext returns a context for releasing server-side resources after the
2881- // user's request has finished.
2882- func cleanupContext (parent context.Context ) (context.Context , context.CancelFunc ) {
2883- return cleanupctx .CleanupContext (parent )
2884- }
2870+ // defaultGracePeriod is used as the default timeout for clean up server resources.
2871+ const defaultGracePeriod = 5 * time .Second
28852872
2886- // cleanupTimeout returns a timeout for releasing server-side resources after the
2873+ // GetCleanupContext returns a context for releasing server-side resources after the
28872874// user's request has finished.
2888- func cleanupTimeout () time. Duration {
2889- return cleanupctx . CleanupTimeout ( )
2875+ func ( fbConn * FbConn ) GetCleanupContext ( parent context. Context ) (context. Context , context. CancelFunc ) {
2876+ return context . WithTimeout ( context . WithoutCancel ( parent ), fbConn . GetCleanupTimeout () )
28902877}
28912878
28922879// commitInternalTx rolls back a rejected implicit commit so the next request
@@ -2923,7 +2910,7 @@ func (fbConn *FbConn) rollbackOwnedInternalTx(ctx context.Context, tx *FBTransac
29232910 if ! fbConn .config .Autocommit || fbConn .explicitTransaction || fbConn .IsClosed () {
29242911 return nil
29252912 }
2926- cleanupCtx , cancel := cleanupContext (ctx )
2913+ cleanupCtx , cancel := fbConn . GetCleanupContext (ctx )
29272914 defer cancel ()
29282915 if err := tx .Rollback (cleanupCtx ); err != nil {
29292916 // A failed rollback leaves the state of the implicit transaction unknown,
@@ -2943,7 +2930,7 @@ func (rr *ResultReader) Close() (QueryStatus, error) {
29432930 rr .fbConn .unlock ()
29442931
29452932 if rr .ownsStatement != nil && ! rr .ownsStatement .closed {
2946- ctx , cancel := cleanupContext (rr .ctx )
2933+ ctx , cancel := rr . fbConn . GetCleanupContext (rr .ctx )
29472934 if dErr := rr .ownsStatement .Deallocate (ctx ); dErr != nil {
29482935 rr .err = operationerror .Join (rr .err , dErr )
29492936 }
@@ -2974,7 +2961,7 @@ func (rr *ResultReader) closeWithoutCommit() (QueryStatus, error) {
29742961 rr .fbConn .contextWatcher .Unwatch ()
29752962 cleanupWatcher := ctxwatch .NewContextWatcher (& DeadlineContextWatcherHandler {
29762963 Conn : rr .fbConn .conn ,
2977- DeadlineDelay : cleanupTimeout (),
2964+ DeadlineDelay : rr . fbConn . GetCleanupTimeout (),
29782965 })
29792966 cleanupWatcher .Watch (rr .ctx )
29802967 defer cleanupWatcher .Unwatch ()
@@ -3614,7 +3601,7 @@ func (h *CancelRequestContextWatcherHandler) HandleUnwatchAfterCancel() {
36143601func (h * CancelRequestContextWatcherHandler ) sendCancelOperationWithTimeout (kind int ) error {
36153602 timeout := h .CancelResetTimeout
36163603 if timeout <= 0 {
3617- timeout = cleanupTimeout ()
3604+ timeout = defaultGracePeriod
36183605 }
36193606 ctx , cancel := context .WithTimeout (context .Background (), timeout )
36203607 defer cancel ()
@@ -3758,3 +3745,14 @@ func cloneArrayDimensions(dimensions []map[string]int) []map[string]int {
37583745 }
37593746 return cloned
37603747}
3748+
3749+ // GetCleanupTimeout returns the server resource cleanup timeout
3750+ // set in the current connection's configuration.
3751+ // If the timeout in the configuration is less than or equal to 0,
3752+ // the default timeout of 5 seconds is returned.
3753+ func (fbConn * FbConn ) GetCleanupTimeout () time.Duration {
3754+ if fbConn .config .CleanupTimeout > 0 {
3755+ return fbConn .config .CleanupTimeout
3756+ }
3757+ return defaultGracePeriod
3758+ }
0 commit comments